home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 34 / rfc1144.zip / RFC1144
Text File  |  1990-05-15  |  121KB  |  2,839 lines

  1.  
  2.    Network Working Group                                     V. Jacobson/1/
  3.    Request for Comments: 1144                                           LBL
  4.                                                               February 1990
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.                           Compressing TCP/IP Headers
  14.  
  15.                           for Low-Speed Serial Links
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.    Status of this Memo
  27.  
  28.    This RFC is a proposed elective protocol for the Internet community and
  29.    requests discussion and suggestions for improvement.  It describes a
  30.    method for compressing the headers of TCP/IP datagrams to improve
  31.    performance over low speed serial links.  The motivation, implementation
  32.    and performance of the method are described.  C code for a sample
  33.    implementation is given for reference.  Distribution of this memo is
  34.    unlimited.
  35.  
  36.  
  37.  
  38.  
  39.    NOTE: Both ASCII and Postscript versions of this document are available.
  40.          The ASCII version, obviously, lacks all the figures and all the
  41.      information encoded in typographic variation (italics, boldface,
  42.      etc.).  Since this information was, in the author's opinion, an
  43.      essential part of the document, the ASCII version is at best
  44.      incomplete and at worst misleading.  Anyone who plans to work
  45.      with this protocol is strongly encouraged obtain the Postscript
  46.      version of this RFC.
  47.  
  48.  
  49.  
  50.  
  51.    ----------------------------
  52.      1. This work was supported in part by the U.S. Department of Energy
  53.    under Contract Number DE-AC03-76SF00098.
  54.  
  55.  
  56.  
  57.  
  58.    Contents
  59.  
  60.  
  61.    1  Introduction                                                        1
  62.  
  63.  
  64.    2  The problem                                                         1
  65.  
  66.  
  67.    3  The compression algorithm                                           4
  68.  
  69.       3.1 The basic idea . . . . . . . . . . . . . . . . . . . . . . . .  4
  70.  
  71.       3.2 The ugly details . . . . . . . . . . . . . . . . . . . . . . .  5
  72.  
  73.          3.2.1 Overview. . . . . . . . . . . . . . . . . . . . . . . . .  5
  74.  
  75.          3.2.2 Compressed packet format. . . . . . . . . . . . . . . . .  7
  76.  
  77.          3.2.3 Compressor processing . . . . . . . . . . . . . . . . . .  8
  78.  
  79.          3.2.4 Decompressor processing . . . . . . . . . . . . . . . . . 12
  80.  
  81.  
  82.    4  Error handling                                                     14
  83.  
  84.       4.1 Error detection  . . . . . . . . . . . . . . . . . . . . . . . 14
  85.  
  86.       4.2 Error recovery . . . . . . . . . . . . . . . . . . . . . . . . 17
  87.  
  88.  
  89.    5  Configurable parameters and tuning                                 18
  90.  
  91.       5.1 Compression configuration  . . . . . . . . . . . . . . . . . . 18
  92.  
  93.       5.2 Choosing a maximum transmission unit . . . . . . . . . . . . . 20
  94.  
  95.       5.3 Interaction with data compression  . . . . . . . . . . . . . . 21
  96.  
  97.  
  98.    6  Performance measurements                                           23
  99.  
  100.  
  101.    7  Acknowlegements                                                    25
  102.  
  103.  
  104.    A  Sample Implementation                                              27
  105.  
  106.       A.1 Definitions and State Data . . . . . . . . . . . . . . . . . . 28
  107.  
  108.       A.2 Compression  . . . . . . . . . . . . . . . . . . . . . . . . . 31
  109.  
  110.  
  111.                                       i
  112.  
  113.  
  114.  
  115.  
  116.       A.3 Decompression  . . . . . . . . . . . . . . . . . . . . . . . . 37
  117.  
  118.       A.4 Initialization . . . . . . . . . . . . . . . . . . . . . . . . 41
  119.  
  120.       A.5 Berkeley Unix dependencies . . . . . . . . . . . . . . . . . . 41
  121.  
  122.  
  123.    B  Compatibility with past mistakes                                   43
  124.  
  125.       B.1 Living without a framing `type' byte . . . . . . . . . . . . . 43
  126.  
  127.       B.2 Backwards compatible SLIP servers  . . . . . . . . . . . . . . 43
  128.  
  129.  
  130.    C  More aggressive compression                                        45
  131.  
  132.  
  133.    D  Security Considerations                                            46
  134.  
  135.  
  136.    E  Author's address                                                   46
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.                                       ii
  170.  
  171.    RFC 1144               Compressing TCP/IP Headers          February 1990
  172.  
  173.  
  174.    1  Introduction
  175.  
  176.  
  177.    As increasingly powerful computers find their way into people's homes,
  178.    there is growing interest in extending Internet connectivity to those
  179.    computers.  Unfortunately, this extension exposes some complex problems
  180.    in link-level framing, address assignment, routing, authentication and
  181.    performance.  As of this writing there is active work in all these
  182.    areas.  This memo describes a method that has been used to improve
  183.    TCP/IP performance over low speed (300 to 19,200 bps) serial links.
  184.  
  185.    The compression proposed here is similar in spirit to the Thinwire-II
  186.    protocol described in [5].  However, this protocol compresses more
  187.    effectively (the average compressed header is 3 bytes compared to 13 in
  188.    Thinwire-II) and is both efficient and simple to implement (the Unix
  189.    implementation is 250 lines of C and requires, on the average, 90us (170
  190.    instructions) for a 20MHz MC68020 to compress or decompress a packet).
  191.  
  192.    This compression is specific to TCP/IP datagrams./2/  The author
  193.    investigated compressing UDP/IP datagrams but found that they were too
  194.    infrequent to be worth the bother and either there was insufficient
  195.    datagram-to-datagram coherence for good compression (e.g., name server
  196.    queries) or the higher level protocol headers overwhelmed the cost of
  197.    the UDP/IP header (e.g., Sun's RPC/NFS). Separately compressing the IP
  198.    and the TCP portions of the datagram was also investigated but rejected
  199.    since it increased the average compressed header size by 50% and doubled
  200.    the compression and decompression code size.
  201.  
  202.  
  203.    2  The problem
  204.  
  205.  
  206.    Internet services one might wish to access over a serial IP link from
  207.    home range from interactive `terminal' type connections (e.g., telnet,
  208.    rlogin, xterm) to bulk data transfer (e.g., ftp, smtp, nntp).  Header
  209.    compression is motivated by the need for good interactive response.
  210.    I.e., the line efficiency of a protocol is the ratio of the data to
  211.    header+data in a datagram.  If efficient bulk data transfer is the only
  212.    objective, it is always possible to make the datagram large enough to
  213.    approach an efficiency of 100%.
  214.  
  215.    Human-factors studies[15] have found that interactive response is
  216.    perceived as `bad' when low-level feedback (character echo) takes longer
  217.  
  218.    ----------------------------
  219.      2. The tie to TCP is deeper than might be obvious.  In addition to the
  220.    compression `knowing' the format of TCP and IP headers, certain features
  221.    of TCP have been used to simplify the compression protocol.  In
  222.    particular, TCP's reliable delivery and the byte-stream conversation
  223.    model have been used to eliminate the need for any kind of error
  224.    correction dialog in the protocol (see sec. 4).
  225.  
  226.  
  227.    Jacobson                                                        [Page 1]
  228.  
  229.    RFC 1144               Compressing TCP/IP Headers          February 1990
  230.  
  231.  
  232.    than 100 to 200 ms.  Protocol headers interact with this threshold three
  233.    ways:
  234.  
  235.    (1) If the line is too slow, it may be impossible to fit both the
  236.        headers and data into a 200 ms window:  One typed character results
  237.        in a 41 byte TCP/IP packet being sent and a 41 byte echo being
  238.        received.  The line speed must be at least 4000 bps to handle these
  239.        82 bytes in 200 ms.
  240.  
  241.    (2) Even with a line fast enough to handle packetized typing echo (4800
  242.        bps or above), there may be an undesirable interaction between bulk
  243.        data and interactive traffic:  For reasonable line efficiency the
  244.        bulk data packet size needs to be 10 to 20 times the header size.
  245.        I.e., the line maximum transmission unit or MTU should be 500 to
  246.        1000 bytes for 40 byte TCP/IP headers.  Even with type-of-service
  247.        queuing to give priority to interactive traffic, a telnet packet has
  248.        to wait for any in-progress bulk data packet to finish.  Assuming
  249.        data transfer in only one direction, that wait averages half the MTU
  250.        or 500 ms for a 1024 byte MTU at 9600 bps.
  251.  
  252.    (3) Any communication medium has a maximum signalling rate, the Shannon
  253.        limit.  Based on an AT&T study[2], the Shannon limit for a typical
  254.        dialup phone line is around 22,000 bps.  Since a full duplex, 9600
  255.        bps modem already runs at 80% of the limit, modem manufacturers are
  256.        starting to offer asymmetric allocation schemes to increase
  257.        effective bandwidth:  Since a line rarely has equivalent amounts of
  258.        data flowing both directions simultaneously, it is possible to give
  259.        one end of the line more than 11,000 bps by either time-division
  260.        multiplexing a half-duplex line (e.g., the Telebit Trailblazer) or
  261.        offering a low-speed `reverse channel' (e.g., the USR Courier
  262.        HST)./3/ In either case, the modem dynamically tries to guess which
  263.        end of the conversation needs high bandwidth by assuming one end of
  264.        the conversation is a human (i.e., demand is limited to <300 bps by
  265.        typing speed).  The factor-of-forty bandwidth multiplication due to
  266.        protocol headers will fool this allocation heuristic and cause these
  267.        modems to `thrash'.
  268.  
  269.    From the above, it's clear that one design goal of the compression
  270.    should be to limit the bandwidth demand of typing and ack traffic to at
  271.    most 300 bps.  A typical maximum typing speed is around five characters
  272.  
  273.  
  274.  
  275.    ----------------------------
  276.      3. See the excellent discussion of two-wire dialup line capacity in
  277.    [1], chap. 11.  In particular, there is widespread misunderstanding of
  278.    the capabilities of `echo-cancelling' modems (such as those conforming
  279.    to CCITT V.32):  Echo-cancellation can offer each side of a two-wire
  280.    line the full line bandwidth but, since the far talker's signal adds to
  281.    the local `noise', not the full line capacity.  The 22Kbps Shannon limit
  282.    is a hard-limit on data rate through a two-wire telephone connection.
  283.  
  284.  
  285.    Jacobson                                                        [Page 2]
  286.  
  287.    RFC 1144               Compressing TCP/IP Headers          February 1990
  288.  
  289.  
  290.    per second/4/ which leaves a budget 30 - 5 = 25 characters for headers
  291.    or five bytes of header per character typed./5/  Five byte headers solve
  292.    problems (1) and (3) directly and, indirectly, problem (2):  A packet
  293.    size of 100--200 bytes will easily amortize the cost of a five byte
  294.    header and offer a user 95--98% of the line bandwidth for data.  These
  295.    short packets mean little interference between interactive and bulk data
  296.    traffic (see sec. 5.2).
  297.  
  298.    Another design goal is that the compression protocol be based solely on
  299.    information guaranteed to be known to both ends of a single serial link.
  300.    Consider the topology shown in fig. 1 where communicating hosts A and B
  301.    are on separate local area nets (the heavy black lines) and the nets are
  302.    connected by two serial links (the open lines between gateways C--D and
  303.    E--F)./6/ One compression possibility would be to convert each TCP/IP
  304.    conversation into a semantically equivalent conversation in a protocol
  305.    with smaller headers, e.g., to an X.25 call.  But, because of routing
  306.    transients or multipathing, it's entirely possible that some of the A--B
  307.    traffic will follow the A-C-D-B path and some will follow the A-E-F-B
  308.    path.  Similarly, it's possible that A->B traffic will flow A-C-D-B and
  309.    B->A traffic will flow B-F-E-A. None of the gateways can count on seeing
  310.    all the packets in a particular TCP conversation and a compression
  311.    algorithm that works for such a topology cannot be tied to the TCP
  312.    connection syntax.
  313.  
  314.    A physical link treated as two, independent, simplex links (one each
  315.    direction) imposes the minimum requirements on topology, routing and
  316.    pipelining.  The ends of each simplex link only have to agree on the
  317.    most recent packet(s) sent on that link.  Thus, although any compression
  318.    scheme involves shared state, this state is spatially and temporally
  319.  
  320.    ----------------------------
  321.      4. See [13].  Typing bursts or multiple character keystrokes such as
  322.    cursor keys can exceed this average rate by factors of two to four.
  323.    However the bandwidth demand stays approximately constant since the TCP
  324.    Nagle algorithm[8] aggregates traffic with a <200ms interarrival time
  325.    and the improved header-to-data ratio compensates for the increased
  326.    data.
  327.      5. A similar analysis leads to essentially the same header size limit
  328.    for bulk data transfer ack packets.  Assuming that the MTU has been
  329.    selected for `unobtrusive' background file transfers (i.e., chosen so
  330.    the packet time is 200--400 ms --- see sec. 5), there can be at most 5
  331.    data packets per second in the `high bandwidth' direction.  A reasonable
  332.    TCP implementation will ack at most every other data packet so at 5
  333.    bytes per ack the reverse channel bandwidth is 2.5 * 5 = 12.5 bytes/sec.
  334.      6. Note that although the TCP endpoints are A and B, in this example
  335.    compression/decompression must be done at the gateway serial links,
  336.    i.e., between C and D and between E and F. Since A and B are using IP,
  337.    they cannot know that their communication path includes a low speed
  338.    serial link.  It is clearly a requirement that compression not break the
  339.    IP model, i.e., that compression function between intermediate systems
  340.    and not just between end systems.
  341.  
  342.  
  343.    Jacobson                                                        [Page 3]
  344.  
  345.    RFC 1144               Compressing TCP/IP Headers          February 1990
  346.  
  347.  
  348.    local and adheres to Dave Clark's principle of fate sharing[4]:  The two
  349.    ends can only disagree on the state if the link connecting them is
  350.    inoperable, in which case the disagreement doesn't matter.
  351.  
  352.  
  353.  
  354.    3  The compression algorithm
  355.  
  356.  
  357.    3.1  The basic idea
  358.  
  359.    Figure 2 shows a typical (and minimum length) TCP/IP datagram header./7/
  360.    The header size is 40 bytes:  20 bytes of IP and 20 of TCP.
  361.    Unfortunately, since the TCP and IP protocols were not designed by a
  362.    committee, all these header fields serve some useful purpose and it's
  363.    not possible to simply omit some in the name of efficiency.
  364.  
  365.    However, TCP establishes connections and, typically, tens or hundreds of
  366.    packets are exchanged on each connection.  How much of the per-packet
  367.    information is likely to stay constant over the life of a connection?
  368.    Half---the shaded fields in fig. 3.  So, if the sender and receiver keep
  369.    track of active connections/8/ and the receiver keeps a copy of the
  370.    header from the last packet it saw from each connection, the sender gets
  371.    a factor-of-two compression by sending only a small (<= 8 bit)
  372.    connection identifier together with the 20 bytes that change and letting
  373.    the receiver fill in the 20 fixed bytes from the saved header.
  374.  
  375.    One can scavenge a few more bytes by noting that any reasonable
  376.    link-level framing protocol will tell the receiver the length of a
  377.    received message so total length (bytes 2 and 3) is redundant.  But then
  378.    the header checksum (bytes 10 and 11), which protects individual hops
  379.    from processing a corrupted IP header, is essentially the only part of
  380.    the IP header being sent.  It seems rather silly to protect the
  381.    transmission of information that isn't being transmitted.  So, the
  382.    receiver can check the header checksum when the header is actually sent
  383.    (i.e., in an uncompressed datagram) but, for compressed datagrams,
  384.    regenerate it locally at the same time the rest of the IP header is
  385.    being regenerated./9/
  386.  
  387.  
  388.    ----------------------------
  389.      7. The TCP and IP protocols and protocol headers are described in [10]
  390.    and [11].
  391.      8. The 96-bit tuple <src address, dst address, src port, dst port>
  392.    uniquely identifies a TCP connection.
  393.      9. The IP header checksum is not an end-to-end checksum in the sense
  394.    of [14]:  The time-to-live update forces the IP checksum to be
  395.    recomputed at each hop.  The author has had unpleasant personal
  396.    experience with the consequences of violating the end-to-end argument in
  397.    [14] and this protocol is careful to pass the end-to-end TCP checksum
  398.    through unmodified.  See sec. 4.
  399.  
  400.  
  401.    Jacobson                                                        [Page 4]
  402.  
  403.    RFC 1144               Compressing TCP/IP Headers          February 1990
  404.  
  405.  
  406.    This leaves 16 bytes of header information to send.  All of these bytes
  407.    are likely to change over the life of the conversation but they do not
  408.    all change at the same time.  For example, during an FTP data transfer
  409.    only the packet ID, sequence number and checksum change in the
  410.    sender->receiver direction and only the packet ID, ack, checksum and,
  411.    possibly, window, change in the receiver->sender direction.  With a copy
  412.    of the last packet sent for each connection, the sender can figure out
  413.    what fields change in the current packet then send a bitmask indicating
  414.    what changed followed by the changing fields./10/
  415.  
  416.    If the sender only sends fields that differ, the above scheme gets the
  417.    average header size down to around ten bytes.  However, it's worthwhile
  418.    looking at how the fields change:  The packet ID typically comes from a
  419.    counter that is incremented by one for each packet sent.  I.e., the
  420.    difference between the current and previous packet IDs should be a
  421.    small, positive integer, usually <256 (one byte) and frequently = 1.
  422.    For packets from the sender side of a data transfer, the sequence number
  423.    in the current packet will be the sequence number in the previous packet
  424.    plus the amount of data in the previous packet (assuming the packets are
  425.    arriving in order).  Since IP packets can be at most 64K, the sequence
  426.    number change must be < 2^16 (two bytes).  So, if the differences in the
  427.    changing fields are sent rather than the fields themselves, another
  428.    three or four bytes per packet can be saved.
  429.  
  430.    That gets us to the five-byte header target.  Recognizing a couple of
  431.    special cases will get us three byte headers for the two most common
  432.    cases---interactive typing traffic and bulk data transfer---but the
  433.    basic compression scheme is the differential coding developed above.
  434.    Given that this intellectual exercise suggests it is possible to get
  435.    five byte headers, it seems reasonable to flesh out the missing details
  436.    and actually implement something.
  437.  
  438.  
  439.    3.2  The ugly details
  440.  
  441.    3.2.1  Overview
  442.  
  443.    Figure 4 shows a block diagram of the compression software.  The
  444.    networking system calls a SLIP output driver with an IP packet to be
  445.  
  446.    ----------------------------
  447.     10. This is approximately Thinwire-I from [5].  A slight modification
  448.    is to do a `delta encoding' where the sender subtracts the previous
  449.    packet from the current packet (treating each packet as an array of 16
  450.    bit integers), then sends a 20-bit mask indicating the non-zero
  451.    differences followed by those differences.  If distinct conversations
  452.    are separated, this is a fairly effective compression scheme (e.g.,
  453.    typically 12-16 byte headers) that doesn't involve the compressor
  454.    knowing any details of the packet structure.  Variations on this theme
  455.    have been used, successfully, for a number of years (e.g., the Proteon
  456.    router's serial link protocol[3]).
  457.  
  458.  
  459.    Jacobson                                                        [Page 5]
  460.  
  461.    RFC 1144               Compressing TCP/IP Headers          February 1990
  462.  
  463.  
  464.    sent over the serial line.  The packet goes through a compressor which
  465.    checks if the protocol is TCP. Non-TCP packets and `uncompressible' TCP
  466.    packets (described below) are just marked as TYPE_IP and passed to a
  467.    framer.  Compressible TCP packets are looked up in an array of packet
  468.    headers.  If a matching connection is found, the incoming packet is
  469.    compressed, the (uncompressed) packet header is copied into the array,
  470.    and a packet of type COMPRESSED_TCP is sent to the framer.  If no match
  471.    is found, the oldest entry in the array is discarded, the packet header
  472.    is copied into that slot, and a packet of type UNCOMPRESSED_TCP is sent
  473.    to the framer.  (An UNCOMPRESSED_TCP packet is identical to the original
  474.    IP packet except the IP protocol field is replaced with a connection
  475.    number---an index into the array of saved, per-connection packet
  476.    headers.  This is how the sender (re-)synchronizes the receiver and
  477.    `seeds' it with the first, uncompressed packet of a compressed packet
  478.    sequence.)
  479.  
  480.    The framer is responsible for communicating the packet data, type and
  481.    boundary (so the decompressor can learn how many bytes came out of the
  482.    compressor).  Since the compression is a differential coding, the framer
  483.    must not re-order packets (this is rarely a concern over a single serial
  484.    link).  It must also provide good error detection and, if connection
  485.    numbers are compressed, must provide an error indication to the
  486.    decompressor (see sec. 4)./11/
  487.  
  488.    The decompressor does a `switch' on the type of incoming packets:  For
  489.    TYPE_IP, the packet is simply passed through.  For UNCOMPRESSED_TCP, the
  490.    connection number is extracted from the IP protocol field and
  491.    IPPROTO_TCP is restored, then the connection number is used as an index
  492.    into the receiver's array of saved TCP/IP headers and the header of the
  493.    incoming packet is copied into the indexed slot.  For COMPRESSED_TCP,
  494.    the connection number is used as an array index to get the TCP/IP header
  495.    of the last packet from that connection, the info in the compressed
  496.    packet is used to update that header, then a new packet is constructed
  497.    containing the now-current header from the array concatenated with the
  498.    data from the compressed packet.
  499.  
  500.    Note that the communication is simplex---no information flows in the
  501.    decompressor-to-compressor direction.  In particular, this implies that
  502.    the decompressor is relying on TCP retransmissions to correct the saved
  503.    state in the event of line errors (see sec. 4).
  504.  
  505.  
  506.  
  507.  
  508.  
  509.    ----------------------------
  510.     11. Link level framing is outside the scope of this document.  Any
  511.    framing that provides the facilities listed in this paragraph should be
  512.    adequate for the compression protocol.  However, the author encourages
  513.    potential implementors to see [9] for a proposed, standard, SLIP
  514.    framing.
  515.  
  516.  
  517.    Jacobson                                                        [Page 6]
  518.  
  519.    RFC 1144               Compressing TCP/IP Headers          February 1990
  520.  
  521.  
  522.    3.2.2  Compressed packet format
  523.  
  524.    Figure 5 shows the format of a compressed TCP/IP packet.  There is a
  525.    change mask that identifies which of the fields expected to change
  526.    per-packet actually changed, a connection number so the receiver can
  527.    locate the saved copy of the last packet for this TCP connection, the
  528.    unmodified TCP checksum so the end-to-end data integrity check will
  529.    still be valid, then for each bit set in the change mask, the amount the
  530.    associated field changed.  (Optional fields, controlled by the mask, are
  531.    enclosed in dashed lines in the figure.)  In all cases, the bit is set
  532.    if the associated field is present and clear if the field is absent./12/
  533.  
  534.    Since the delta's in the sequence number, etc., are usually small,
  535.    particularly if the tuning guidelines in section 5 are followed, all the
  536.    numbers are encoded in a variable length scheme that, in practice,
  537.    handles most traffic with eight bits:  A change of one through 255 is
  538.    represented in one byte.  Zero is improbable (a change of zero is never
  539.    sent) so a byte of zero signals an extension:  The next two bytes are
  540.    the MSB and LSB, respectively, of a 16 bit value.  Numbers larger than
  541.    16 bits force an uncompressed packet to be sent.  For example, decimal
  542.    15 is encoded as hex 0f, 255 as ff, 65534 as 00 ff fe, and zero as 00 00
  543.    00.  This scheme packs and decodes fairly efficiently:  The usual case
  544.    for both encode and decode executes three instructions on a MC680x0.
  545.  
  546.    The numbers sent for TCP sequence number and ack are the difference/13/
  547.    between the current value and the value in the previous packet (an
  548.    uncompressed packet is sent if the difference is negative or more than
  549.    64K). The number sent for the window is also the difference between the
  550.    current and previous values.  However, either positive or negative
  551.    changes are allowed since the window is a 16 bit field.  The packet's
  552.    urgent pointer is sent if URG is set (an uncompressed packet is sent if
  553.    the urgent pointer changes but URG is not set).  For packet ID, the
  554.    number sent is the difference between the current and previous values.
  555.    However, unlike the rest of the compressed fields, the assumed change
  556.    when I is clear is one, not zero.
  557.  
  558.    There are two important special cases:
  559.  
  560.    (1) The sequence number and ack both change by the amount of data in the
  561.        last packet; no window change or URG.
  562.  
  563.    (2) The sequence number changes by the amount of data in the last
  564.        packet, no ack or window change or URG.
  565.  
  566.    ----------------------------
  567.     12. The bit `P' in the figure is different from the others:  It is a
  568.    copy of the `PUSH' bit from the TCP header.  `PUSH' is a curious
  569.    anachronism considered indispensable by certain members of the Internet
  570.    community.  Since PUSH can (and does) change in any datagram, an
  571.    information preserving compression scheme must pass it explicitly.
  572.     13. All differences are computed using two's complement arithmetic.
  573.  
  574.  
  575.    Jacobson                                                        [Page 7]
  576.  
  577.    RFC 1144               Compressing TCP/IP Headers          February 1990
  578.  
  579.  
  580.    (1) is the case for echoed terminal traffic.  (2) is the sender side of
  581.    non-echoed terminal traffic or a unidirectional data transfer.  Certain
  582.    combinations of the S, A, W and U bits of the change mask are used to
  583.    signal these special cases.  `U' (urgent data) is rare so two unlikely
  584.    combinations are S W U (used for case 1) and S A W U (used for case 2).
  585.    To avoid ambiguity, an uncompressed packet is sent if the actual changes
  586.    in a packet are S * W U.
  587.  
  588.    Since the `active' connection changes rarely (e.g., a user will type for
  589.    several minutes in a telnet window before changing to a different
  590.    window), the C bit allows the connection number to be elided.  If C is
  591.    clear, the connection is assumed to be the same as for the last
  592.    compressed or uncompressed packet.  If C is set, the connection number
  593.    is in the byte immediately following the change mask./14/
  594.  
  595.    From the above, it's probably obvious that compressed terminal traffic
  596.    usually looks like (in hex):  0B c c d, where the 0B indicates case (1),
  597.    c c is the two byte TCP checksum and d is the character typed.  Commands
  598.    to vi or emacs, or packets in the data transfer direction of an FTP
  599.    `put' or `get' look like 0F c c d ... , and acks for that FTP look like
  600.    04 c c a where a is the amount of data being acked./15/
  601.  
  602.  
  603.    3.2.3  Compressor processing
  604.  
  605.    The compressor is called with the IP packet to be processed and the
  606.    compression state structure for the outgoing serial line.  It returns a
  607.    packet ready for final framing and the link level `type' of that packet.
  608.  
  609.    As the last section noted, the compressor converts every input packet
  610.    into either a TYPE_IP, UNCOMPRESSED_TCP or COMPRESSED_TCP packet.  A
  611.  
  612.  
  613.  
  614.    ----------------------------
  615.     14. The connection number is limited to one byte, i.e., 256
  616.    simultaneously active TCP connections.  In almost two years of
  617.    operation, the author has never seen a case where more than sixteen
  618.    connection states would be useful (even in one case where the SLIP link
  619.    was used as a gateway behind a very busy, 64-port terminal multiplexor).
  620.    Thus this does not seem to be a significant restriction and allows the
  621.    protocol field in UNCOMPRESSED_TCP packets to be used for the connection
  622.    number, simplifying the processing of those packets.
  623.     15. It's also obvious that the change mask changes infrequently and
  624.    could often be elided.  In fact, one can do slightly better by saving
  625.    the last compressed packet (it can be at most 16 bytes so this isn't
  626.    much additional state) and checking to see if any of it (except the TCP
  627.    checksum) has changed.  If not, send a packet type that means
  628.    `compressed TCP, same as last time' and a packet containing only the
  629.    checksum and data.  But, since the improvement is at most 25%, the added
  630.    complexity and state doesn't seem justified.  See appendix C.
  631.  
  632.  
  633.    Jacobson                                                        [Page 8]
  634.  
  635.    RFC 1144               Compressing TCP/IP Headers          February 1990
  636.  
  637.  
  638.    TYPE_IP packet is an unmodified copy/16/ of the input packet and
  639.    processing it doesn't change the compressor's state in any way.
  640.  
  641.    An UNCOMPRESSED_TCP packet is identical to the input packet except the
  642.    IP protocol field (byte 9) is changed from `6' (protocol TCP) to a
  643.    connection number.  In addition, the state slot associated with the
  644.    connection number is updated with a copy of the input packet's IP and
  645.    TCP headers and the connection number is recorded as the last connection
  646.    sent on this serial line (for the C compression described below).
  647.  
  648.    A COMPRESSED_TCP packet contains the data, if any, from the original
  649.    packet but the IP and TCP headers are completely replaced with a new,
  650.    compressed header.  The connection state slot and last connection sent
  651.    are updated by the input packet exactly as for an UNCOMPRESSED_TCP
  652.    packet.
  653.  
  654.    The compressor's decision procedure is:
  655.  
  656.      - If the packet is not protocol TCP, send it as TYPE_IP.
  657.  
  658.      - If the packet is an IP fragment (i.e., either the fragment offset
  659.        field is non-zero or the more fragments bit is set), send it as
  660.        TYPE_IP./17/
  661.  
  662.      - If any of the TCP control bits SYN, FIN or RST are set or if the ACK
  663.        bit is clear, consider the packet uncompressible and send it as
  664.        TYPE_IP./18/
  665.  
  666.    ----------------------------
  667.     16. It is not necessary (or desirable) to actually duplicate the input
  668.    packet for any of the three output types.  Note that the compressor
  669.    cannot increase the size of a datagram.  As the code in appendix A
  670.    shows, the protocol can be implemented so all header modifications are
  671.    made `in place'.
  672.     17. Only the first fragment contains the TCP header so the fragment
  673.    offset check is necessary.  The first fragment might contain a complete
  674.    TCP header and, thus, could be compressed.  However the check for a
  675.    complete TCP header adds quite a lot of code and, given the arguments in
  676.    [6], it seems reasonable to send all IP fragments uncompressed.
  677.     18. The ACK test is redundant since a standard conforming
  678.    implementation must set ACK in all packets except for the initial SYN
  679.    packet.  However, the test costs nothing and avoids turning a bogus
  680.    packet into a valid one.
  681.    SYN packets are not compressed because only half of them contain a valid
  682.    ACK field and they usually contain a TCP option (the max. segment size)
  683.    which the following packets don't.  Thus the next packet would be sent
  684.    uncompressed because the TCP header length changed and sending the SYN
  685.    as UNCOMPRESSED_TCP instead of TYPE_IP would buy nothing.
  686.    The decision to not compress FIN packets is questionable.  Discounting
  687.    the trick in appendix B.1, there is a free bit in the header that could
  688.    be used to communicate the FIN flag.  However, since connections tend to
  689.  
  690.  
  691.    Jacobson                                                        [Page 9]
  692.  
  693.    RFC 1144               Compressing TCP/IP Headers          February 1990
  694.  
  695.  
  696.    If a packet makes it through the above checks, it will be sent as either
  697.    UNCOMPRESSED_TCP or COMPRESSED_TCP:
  698.  
  699.      - If no connection state can be found that matches the packet's source
  700.        and destination IP addresses and TCP ports, some state is reclaimed
  701.        (which should probably be the least recently used) and an
  702.        UNCOMPRESSED_TCP packet is sent.
  703.  
  704.      - If a connection state is found, the packet header it contains is
  705.        checked against the current packet to make sure there were no
  706.        unexpected changes.  (E.g., that all the shaded fields in fig. 3 are
  707.        the same).  The IP protocol, fragment offset, more fragments, SYN,
  708.        FIN and RST fields were checked above and the source and destination
  709.        address and ports were checked as part of locating the state.  So
  710.        the remaining fields to check are protocol version, header length,
  711.        type of service, don't fragment, time-to-live, data offset, IP
  712.        options (if any) and TCP options (if any).  If any of these fields
  713.        differ between the two headers, an UNCOMPRESSED_TCP packet is sent.
  714.  
  715.    If all the `unchanging' fields match, an attempt is made to compress the
  716.    current packet:
  717.  
  718.      - If the URG flag is set, the urgent data field is encoded (note that
  719.        it may be zero) and the U bit is set in the change mask.
  720.        Unfortunately, if URG is clear, the urgent data field must be
  721.        checked against the previous packet and, if it changes, an
  722.        UNCOMPRESSED_TCP packet is sent.  (`Urgent data' shouldn't change
  723.        when URG is clear but [11] doesn't require this.)
  724.  
  725.      - The difference between the current and previous packet's window
  726.        field is computed and, if non-zero, is encoded and the W bit is set
  727.        in the change mask.
  728.  
  729.      - The difference between ack fields is computed.  If the result is
  730.        less than zero or greater than 2^16 - 1, an UNCOMPRESSED_TCP packet
  731.        is sent./19/  Otherwise, if the result is non-zero, it is encoded
  732.        and the A bit is set in the change mask.
  733.  
  734.      - The difference between sequence number fields is computed.  If the
  735.        result is less than zero or greater than 2^16 - 1, an
  736.  
  737.  
  738.  
  739.  
  740.  
  741.  
  742.    ----------------------------
  743.    last for many packets, it seemed unreasonable to dedicate an entire bit
  744.    to a flag that would only appear once in the lifetime of the connection.
  745.     19. The two tests can be combined into a single test of the most
  746.    significant 16 bits of the difference being non-zero.
  747.  
  748.  
  749.    Jacobson                                                       [Page 10]
  750.  
  751.    RFC 1144               Compressing TCP/IP Headers          February 1990
  752.  
  753.  
  754.        UNCOMPRESSED_TCP packet is sent./20/  Otherwise, if the result is
  755.        non-zero, it is encoded and the S bit is set in the change mask.
  756.  
  757.    Once the U, W, A and S changes have been determined, the special-case
  758.    encodings can be checked:
  759.  
  760.      - If U, S and W are set, the changes match one of the special-case
  761.        encodings.  Send an UNCOMPRESSED_TCP packet.
  762.  
  763.      - If only S is set, check if the change equals the amount of user data
  764.        in the last packet.  I.e., subtract the TCP and IP header lengths
  765.        from the last packet's total length field and compare the result to
  766.        the S change.  If they're the same, set the change mask to SAWU (the
  767.        special case for `unidirectional data transfer') and discard the
  768.        encoded sequence number change (the decompressor can reconstruct it
  769.        since it knows the last packet's total length and header length).
  770.  
  771.      - If only S and A are set, check if they both changed by the same
  772.        amount and that amount is the amount of user data in the last
  773.        packet.  If so, set the change mask to SWU (the special case for
  774.        `echoed interactive' traffic) and discard the encoded changes.
  775.  
  776.      - If nothing changed, check if this packet has no user data (in which
  777.        case it is probably a duplicate ack or window probe) or if the
  778.        previous packet contained user data (which means this packet is a
  779.        retransmission on a connection with no pipelining).  In either of
  780.        these cases, send an UNCOMPRESSED_TCP packet.
  781.  
  782.    Finally, the TCP/IP header on the outgoing packet is replaced with a
  783.    compressed header:
  784.  
  785.      - The change in the packet ID is computed and, if not one,/21/ the
  786.        difference is encoded (note that it may be zero or negative) and the
  787.        I bit is set in the change mask.
  788.  
  789.      - If the PUSH bit is set in the original datagram, the P bit is set in
  790.        the change mask.
  791.  
  792.      - The TCP and IP headers of the packet are copied to the connection
  793.        state slot.
  794.  
  795.  
  796.    ----------------------------
  797.     20. A negative sequence number change probably indicates a
  798.    retransmission.  Since this may be due to the decompressor having
  799.    dropped a packet, an uncompressed packet is sent to re-sync the
  800.    decompressor (see sec. 4).
  801.     21. Note that the test here is against one, not zero.  The packet ID is
  802.    typically incremented by one for each packet sent so a change of zero is
  803.    very unlikely.  A change of one is likely:  It occurs during any period
  804.    when the originating system has activity on only one connection.
  805.  
  806.  
  807.    Jacobson                                                       [Page 11]
  808.  
  809.    RFC 1144               Compressing TCP/IP Headers          February 1990
  810.  
  811.  
  812.      - The TCP and IP headers of the packet are discarded and a new header
  813.        is prepended consisting of (in reverse order):
  814.  
  815.          - the accumulated, encoded changes.
  816.  
  817.          - the TCP checksum (if the new header is being constructed `in
  818.            place', the checksum may have been overwritten and will have to
  819.            be taken from the header copy in the connection state or saved
  820.            in a temporary before the original header is discarded).
  821.  
  822.          - the connection number (if different than the last one sent on
  823.            this serial line).  This also means that the the line's last
  824.            connection sent must be set to the connection number and the C
  825.            bit set in the change mask.
  826.  
  827.          - the change mask.
  828.  
  829.    At this point, the compressed TCP packet is passed to the framer for
  830.    transmission.
  831.  
  832.  
  833.    3.2.4  Decompressor processing
  834.  
  835.    Because of the simplex communication model, processing at the
  836.    decompressor is much simpler than at the compressor --- all the
  837.    decisions have been made and the decompressor simply does what the
  838.    compressor has told it to do.
  839.  
  840.    The decompressor is called with the incoming packet,/22/ the length and
  841.    type of the packet and the compression state structure for the incoming
  842.    serial line.  A (possibly re-constructed) IP packet will be returned.
  843.  
  844.    The decompressor can receive four types of packet:  the three generated
  845.    by the compressor and a TYPE_ERROR pseudo-packet generated when the
  846.    receive framer detects an error./23/  The first step is a `switch' on
  847.    the packet type:
  848.  
  849.      - If the packet is TYPE_ERROR or an unrecognized type, a `toss' flag
  850.        is set in the state to force COMPRESSED_TCP packets to be discarded
  851.        until one with the C bit set or an UNCOMPRESSED_TCP packet arrives.
  852.        Nothing (a null packet) is returned.
  853.  
  854.    ----------------------------
  855.     22. It's assumed that link-level framing has been removed by this point
  856.    and the packet and length do not include type or framing bytes.
  857.     23. No data need be associated with a TYPE_ERROR packet.  It exists so
  858.    the receive framer can tell the decompressor that there may be a gap in
  859.    the data stream.  The decompressor uses this as a signal that packets
  860.    should be tossed until one arrives with an explicit connection number (C
  861.    bit set).  See the last part of sec. 4.1 for a discussion of why this is
  862.    necessary.
  863.  
  864.  
  865.    Jacobson                                                       [Page 12]
  866.  
  867.    RFC 1144               Compressing TCP/IP Headers          February 1990
  868.  
  869.  
  870.      - If the packet is TYPE_IP, an unmodified copy of it is returned and
  871.        the state is not modified.
  872.  
  873.      - If the packet is UNCOMPRESSED_TCP, the state index from the IP
  874.        protocol field is checked./24/  If it's illegal, the toss flag is
  875.        set and nothing is returned.  Otherwise, the toss flag is cleared,
  876.        the index is copied to the state's last connection received field, a
  877.        copy of the input packet is made,/25/ the TCP protocol number is
  878.        restored to the IP protocol field, the packet header is copied to
  879.        the indicated state slot, then the packet copy is returned.
  880.  
  881.    If the packet was not handled above, it is COMPRESSED_TCP and a new
  882.    TCP/IP header has to be synthesized from information in the packet plus
  883.    the last packet's header in the state slot.  First, the explicit or
  884.    implicit connection number is used to locate the state slot:
  885.  
  886.      - If the C bit is set in the change mask, the state index is checked.
  887.        If it's illegal, the toss flag is set and nothing is returned.
  888.        Otherwise, last connection received is set to the packet's state
  889.        index and the toss flag is cleared.
  890.  
  891.      - If the C bit is clear and the toss flag is set, the packet is
  892.        ignored and nothing is returned.
  893.  
  894.    At this point, last connection received is the index of the appropriate
  895.    state slot and the first byte(s) of the compressed packet (the change
  896.    mask and, possibly, connection index) have been consumed.  Since the
  897.    TCP/IP header in the state slot must end up reflecting the newly arrived
  898.    packet, it's simplest to apply the changes from the packet to that
  899.    header then construct the output packet from that header concatenated
  900.    with the data from the input packet.  (In the following description,
  901.    `saved header' is used as an abbreviation for `the TCP/IP header saved
  902.    in the state slot'.)
  903.  
  904.      - The next two bytes in the incoming packet are the TCP checksum.
  905.        They are copied to the saved header.
  906.  
  907.      - If the P bit is set in the change mask, the TCP PUSH bit is set in
  908.        the saved header.  Otherwise the PUSH bit is cleared.
  909.  
  910.  
  911.  
  912.  
  913.    ----------------------------
  914.     24. State indices follow the C language convention and run from 0 to N
  915.    - 1, where 0 < N <= 256 is the number of available state slots.
  916.     25. As with the compressor, the code can be structured so no copies are
  917.    done and all modifications are done in-place.  However, since the output
  918.    packet can be larger than the input packet, 128 bytes of free space must
  919.    be left at the front of the input packet buffer to allow room to prepend
  920.    the TCP/IP header.
  921.  
  922.  
  923.    Jacobson                                                       [Page 13]
  924.  
  925.    RFC 1144               Compressing TCP/IP Headers          February 1990
  926.  
  927.  
  928.      - If the low order four bits (S, A, W and U) of the change mask are
  929.        all set (the `unidirectional data' special case), the amount of user
  930.        data in the last packet is calculated by subtracting the TCP and IP
  931.        header lengths from the IP total length in the saved header.  That
  932.        amount is then added to the TCP sequence number in the saved header.
  933.  
  934.      - If S, W and U are set and A is clear (the `terminal traffic' special
  935.        case), the amount of user data in the last packet is calculated and
  936.        added to both the TCP sequence number and ack fields in the saved
  937.        header.
  938.  
  939.      - Otherwise, the change mask bits are interpreted individually in the
  940.        order that the compressor set them:
  941.  
  942.          - If the U bit is set, the TCP URG bit is set in the saved header
  943.            and the next byte(s) of the incoming packet are decoded and
  944.            stuffed into the TCP Urgent Pointer.  If the U bit is clear, the
  945.            TCP URG bit is cleared.
  946.  
  947.          - If the W bit is set, the next byte(s) of the incoming packet are
  948.            decoded and added to the TCP window field of the saved header.
  949.  
  950.          - If the A bit is set, the next byte(s) of the incoming packet are
  951.            decoded and added to the TCP ack field of the saved header.
  952.  
  953.          - If the S bit is set, the next byte(s) of the incoming packet are
  954.            decoded and added to the TCP sequence number field of the saved
  955.            header.
  956.  
  957.      - If the I bit is set in the change mask, the next byte(s) of the
  958.        incoming packet are decoded and added to the IP ID field of the
  959.        saved packet.  Otherwise, one is added to the IP ID.
  960.  
  961.    At this point, all the header information from the incoming packet has
  962.    been consumed and only data remains.  The length of the remaining data
  963.    is added to the length of the saved IP and TCP headers and the result is
  964.    put into the saved IP total length field.  The saved IP header is now up
  965.    to date so its checksum is recalculated and stored in the IP checksum
  966.    field.  Finally, an output datagram consisting of the saved header
  967.    concatenated with the remaining incoming data is constructed and
  968.    returned.
  969.  
  970.  
  971.    4  Error handling
  972.  
  973.  
  974.    4.1  Error detection
  975.  
  976.    In the author's experience, dialup connections are particularly prone to
  977.    data errors.  These errors interact with compression in two different
  978.    ways:
  979.  
  980.  
  981.    Jacobson                                                       [Page 14]
  982.  
  983.    RFC 1144               Compressing TCP/IP Headers          February 1990
  984.  
  985.  
  986.    First is the local effect of an error in a compressed packet.  All error
  987.    detection is based on redundancy yet compression has squeezed out almost
  988.    all the redundancy in the TCP and IP headers.  In other words, the
  989.    decompressor will happily turn random line noise into a perfectly valid
  990.    TCP/IP packet./26/  One could rely on the TCP checksum to detect
  991.    corrupted compressed packets but, unfortunately, some rather likely
  992.    errors will not be detected.  For example, the TCP checksum will often
  993.    not detect two single bit errors separated by 16 bits.  For a V.32 modem
  994.    signalling at 2400 baud with 4 bits/baud, any line hit lasting longer
  995.    than 400us. would corrupt 16 bits.  According to [2], residential phone
  996.    line hits of up to 2ms. are likely.
  997.  
  998.    The correct way to deal with this problem is to provide for error
  999.    detection at the framing level.  Since the framing (at least in theory)
  1000.    can be tailored to the characteristics of a particular link, the
  1001.    detection can be as light or heavy-weight as appropriate for that
  1002.    link./27/  Since packet error detection is done at the framing level,
  1003.    the decompressor simply assumes that it will get an indication that the
  1004.    current packet was received with errors.  (The decompressor always
  1005.    ignores (discards) a packet with errors.  However, the indication is
  1006.    needed to prevent the error being propagated --- see below.)
  1007.  
  1008.    The `discard erroneous packets' policy gives rise to the second
  1009.    interaction of errors and compression.  Consider the following
  1010.    conversation:
  1011.  
  1012.                  +-------------------------------------------+
  1013.                  |original | sent   |received |reconstructed |
  1014.                  +---------+--------+---------+--------------+
  1015.                  | 1:  A   | 1:  A  | 1:  A   | 1:  A        |
  1016.                  | 2:  BC  | 1,  BC | 1,  BC  | 2:  BC       |
  1017.                  | 4:  DE  | 2,  DE |  ---    |  ---         |
  1018.                  | 6:  F   | 2,  F  | 2,  F   | 4:  F        |
  1019.                  | 7:  GH  | 1,  GH | 1,  GH  | 5:  GH       |
  1020.                  +-------------------------------------------+
  1021.  
  1022.    (Each entry above has the form `starting sequence number:data sent' or
  1023.    `?sequence number change,data sent'.)  The first thing sent is an
  1024.    uncompressed packet, followed by four compressed packets.  The third
  1025.    packet picks up an error and is discarded.  To reconstruct the fourth
  1026.    packet, the receiver applies the sequence number change from incoming
  1027.    compressed packet to the sequence number of the last correctly received
  1028.  
  1029.    ----------------------------
  1030.     26. modulo the TCP checksum.
  1031.     27. While appropriate error detection is link dependent, the CCITT CRC
  1032.    used in [9] strikes an excellent balance between ease of computation and
  1033.    robust error detection for a large variety of links, particularly at the
  1034.    relatively small packet sizes needed for good interactive response.
  1035.    Thus, for the sake of interoperability, the framing in [9] should be
  1036.    used unless there is a truly compelling reason to do otherwise.
  1037.  
  1038.  
  1039.    Jacobson                                                       [Page 15]
  1040.  
  1041.    RFC 1144               Compressing TCP/IP Headers          February 1990
  1042.  
  1043.  
  1044.    packet, packet two, and generates an incorrect sequence number for
  1045.    packet four.  After the error, all reconstructed packets' sequence
  1046.    numbers will be in error, shifted down by the amount of data in the
  1047.    missing packet./28/
  1048.  
  1049.    Without some sort of check, the preceding error would result in the
  1050.    receiver invisibly losing two bytes from the middle of the transfer
  1051.    (since the decompressor regenerates sequence numbers, the packets
  1052.    containing F and GH arrive at the receiver's TCP with exactly the
  1053.    sequence numbers they would have had if the DE packet had never
  1054.    existed).  Although some TCP conversations can survive missing data/29/
  1055.    it is not a practice to be encouraged.  Fortunately the TCP checksum,
  1056.    since it is a simple sum of the packet contents including the sequence
  1057.    numbers, detects 100% of these errors.  E.g., the receiver's computed
  1058.    checksum for the last two packets above always differs from the packet
  1059.    checksum by two.
  1060.  
  1061.    Unfortunately, there is a way for the TCP checksum protection described
  1062.    above to fail if the changes in an incoming compressed packet are
  1063.    applied to the wrong conversation:  Consider two active conversations C1
  1064.    and C2 and a packet from C1 followed by two packets from C2.  Since the
  1065.    connection number doesn't change, it's omitted from the second C2
  1066.    packet.  But, if the first C2 packet is received with a CRC error, the
  1067.    second C2 packet will mistakenly be considered the next packet in C1.
  1068.    Since the C2 checksum is a random number with respect to the C1 sequence
  1069.    numbers, there is at least a 2^-16 probability that this packet will be
  1070.    accepted by the C1 TCP receiver./30/  To prevent this, after a CRC error
  1071.    indication from the framer the receiver discards packets until it
  1072.    receives either a COMPRESSED_TCP packet with the C bit set or an
  1073.    UNCOMPRESSED_TCP packet.  I.e., packets are discarded until the receiver
  1074.    gets an explicit connection number.
  1075.  
  1076.    To summarize this section, there are two different types of errors:
  1077.    per-packet corruption and per-conversation loss-of-sync.  The first type
  1078.    is detected at the decompressor from a link-level CRC error, the second
  1079.    at the TCP receiver from a (guaranteed) invalid TCP checksum.  The
  1080.    combination of these two independent mechanisms ensures that erroneous
  1081.    packets are discarded.
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.    ----------------------------
  1088.     28. This is an example of a generic problem with differential or delta
  1089.    encodings known as `losing DC'.
  1090.     29. Many system managers claim that holes in an NNTP stream are more
  1091.    valuable than the data.
  1092.     30. With worst-case traffic, this probability translates to one
  1093.    undetected error every three hours over a 9600 baud line with a 30%
  1094.    error rate).
  1095.  
  1096.  
  1097.    Jacobson                                                       [Page 16]
  1098.  
  1099.    RFC 1144               Compressing TCP/IP Headers          February 1990
  1100.  
  1101.  
  1102.    4.2  Error recovery
  1103.  
  1104.    The previous section noted that after a CRC error the decompressor will
  1105.    introduce TCP checksum errors in every uncompressed packet.  Although
  1106.    the checksum errors prevent data stream corruption, the TCP conversation
  1107.    won't be terribly useful until the decompressor again generates valid
  1108.    packets.  How can this be forced to happen?
  1109.  
  1110.    The decompressor generates invalid packets because its state (the saved
  1111.    `last packet header') disagrees with the compressor's state.  An
  1112.    UNCOMPRESSED_TCP packet will correct the decompressor's state.  Thus
  1113.    error recovery amounts to forcing an uncompressed packet out of the
  1114.    compressor whenever the decompressor is (or might be) confused.
  1115.  
  1116.    The first thought is to take advantage of the full duplex communication
  1117.    link and have the decompressor send something to the compressor
  1118.    requesting an uncompressed packet.  This is clearly undesirable since it
  1119.    constrains the topology more than the minimum suggested in sec. 2 and
  1120.    requires that a great deal of protocol be added to both the decompressor
  1121.    and compressor.  A little thought convinces one that this alternative is
  1122.    not only undesirable, it simply won't work:  Compressed packets are
  1123.    small and it's likely that a line hit will so completely obliterate one
  1124.    that the decompressor will get nothing at all.  Thus packets are
  1125.    reconstructed incorrectly (because of the missing compressed packet) but
  1126.    only the TCP end points, not the decompressor, know that the packets are
  1127.    incorrect.
  1128.  
  1129.    But the TCP end points know about the error and TCP is a reliable
  1130.    protocol designed to run over unreliable media.  This means the end
  1131.    points must eventually take some sort of error recovery action and
  1132.    there's an obvious trigger for the compressor to resync the
  1133.    decompressor:  send uncompressed packets whenever TCP is doing error
  1134.    recovery.
  1135.  
  1136.    But how does the compressor recognize TCP error recovery?  Consider the
  1137.    schematic TCP data transfer of fig. 6.    The confused decompressor is
  1138.    in the forward (data transfer) half of the TCP conversation.  The
  1139.    receiving TCP discards packets rather than acking them (because of the
  1140.    checksum errors), the sending TCP eventually times out and retransmits a
  1141.    packet, and the forward path compressor finds that the difference
  1142.    between the sequence number in the retransmitted packet and the sequence
  1143.    number in the last packet seen is either negative (if there were
  1144.    multiple packets in transit) or zero (one packet in transit).  The first
  1145.    case is detected in the compression step that computes sequence number
  1146.    differences.  The second case is detected in the step that checks the
  1147.    `special case' encodings but needs an additional test:  It's fairly
  1148.    common for an interactive conversation to send a dataless ack packet
  1149.    followed by a data packet.  The ack and data packet will have the same
  1150.    sequence numbers yet the data packet is not a retransmission.  To
  1151.    prevent sending an unnecessary uncompressed packet, the length of the
  1152.    previous packet should be checked and, if it contained data, a zero
  1153.  
  1154.  
  1155.    Jacobson                                                       [Page 17]
  1156.  
  1157.    RFC 1144               Compressing TCP/IP Headers          February 1990
  1158.  
  1159.  
  1160.    sequence number change must indicate a retransmission.
  1161.  
  1162.    A confused decompressor in the reverse (ack) half of the conversation is
  1163.    as easy to detect (fig. 7):    The sending TCP discards acks (because
  1164.    they contain checksum errors), eventually times out, then retransmits
  1165.    some packet.  The receiving TCP thus gets a duplicate packet and must
  1166.    generate an ack for the next expected sequence number[11, p. 69].  This
  1167.    ack will be a duplicate of the last ack the receiver generated so the
  1168.    reverse-path compressor will find no ack, seq number, window or urg
  1169.    change.  If this happens for a packet that contains no data, the
  1170.    compressor assumes it is a duplicate ack sent in response to a
  1171.    retransmit and sends an UNCOMPRESSED_TCP packet./31/
  1172.  
  1173.  
  1174.  
  1175.    5  Configurable parameters and tuning
  1176.  
  1177.  
  1178.    5.1  Compression configuration
  1179.  
  1180.    There are two configuration parameters associated with header
  1181.    compression:  Whether or not compressed packets should be sent on a
  1182.    particular line and, if so, how many state slots (saved packet headers)
  1183.    to reserve.  There is also one link-level configuration parameter, the
  1184.    maximum packet size or MTU, and one front-end configuration parameter,
  1185.    data compression, that interact with header compression.  Compression
  1186.    configuration is discussed in this section.  MTU and data compression
  1187.    are discussed in the next two sections.
  1188.  
  1189.    There are some hosts (e.g., low end PCs) which may not have enough
  1190.    processor or memory resources to implement this compression.  There are
  1191.    also rare link or application characteristics that make header
  1192.    compression unnecessary or undesirable.  And there are many existing
  1193.    SLIP links that do not currently use this style of header compression.
  1194.    For the sake of interoperability, serial line IP drivers that allow
  1195.    header compression should include some sort of user configurable flag to
  1196.    disable compression (see appendix B.2)./32/
  1197.  
  1198.    If compression is enabled, the compressor must be sure to never send a
  1199.    connection id (state index) that will be dropped by the decompressor.
  1200.    E.g., a black hole is created if the decompressor has sixteen slots and
  1201.  
  1202.    ----------------------------
  1203.     31. The packet could be a zero-window probe rather than a retransmitted
  1204.    ack but window probes should be infrequent and it does no harm to send
  1205.    them uncompressed.
  1206.     32. The PPP protocol in [9] allows the end points to negotiate
  1207.    compression so there is no interoperability problem.  However, there
  1208.    should still be a provision for the system manager at each end to
  1209.    control whether compression is negotiated on or off.  And, obviously,
  1210.    compression should default to `off' until it has been negotiated `on'.
  1211.  
  1212.  
  1213.    Jacobson                                                       [Page 18]
  1214.  
  1215.    RFC 1144               Compressing TCP/IP Headers          February 1990
  1216.  
  1217.  
  1218.    the compressor uses twenty./33/  Also, if the compressor is allowed too
  1219.    few slots, the LRU allocator will thrash and most packets will be sent
  1220.    as UNCOMPRESSED_TCP. Too many slots and memory is wasted.
  1221.  
  1222.    Experimenting with different sizes over the past year, the author has
  1223.    found that eight slots will thrash (i.e., the performance degradation is
  1224.    noticeable) when many windows on a multi-window workstation are
  1225.    simultaneously in use or the workstation is being used as a gateway for
  1226.    three or more other machines.  Sixteen slots were never observed to
  1227.    thrash.  (This may simply be because a 9600 bps line split more than 16
  1228.    ways is already so overloaded that the additional degradation from
  1229.    round-robbining slots is negligible.)
  1230.  
  1231.    Each slot must be large enough to hold a maximum length TCP/IP header of
  1232.    128 bytes/34/ so 16 slots occupy 2KB of memory.  In these days of 4 Mbit
  1233.    RAM chips, 2KB seems so little memory that the author recommends the
  1234.    following configuration rules:
  1235.  
  1236.    (1) If the framing protocol does not allow negotiation, the compressor
  1237.        and decompressor should provide sixteen slots, zero through fifteen.
  1238.  
  1239.    (2) If the framing protocol allows negotiation, any mutually agreeable
  1240.        number of slots from 1 to 256 should be negotiable./35/  If number
  1241.        of slots is not negotiated, or until it is negotiated, both sides
  1242.        should assume sixteen.
  1243.  
  1244.    (3) If you have complete control of all the machines at both ends of
  1245.        every link and none of them will ever be used to talk to machines
  1246.        outside of your control, you are free to configure them however you
  1247.        please, ignoring the above.  However, when your little eastern-block
  1248.        dictatorship collapses (as they all eventually seem to), be aware
  1249.        that a large, vocal, and not particularly forgiving Internet
  1250.        community will take great delight in pointing out to anyone willing
  1251.  
  1252.  
  1253.    ----------------------------
  1254.     33. Strictly speaking, there's no reason why the connection id should
  1255.    be treated as an array index.  If the decompressor's states were kept in
  1256.    a hash table or other associative structure, the connection id would be
  1257.    a key, not an index, and performance with too few decompressor slots
  1258.    would only degrade enormously rather than failing altogether.  However,
  1259.    an associative structure is substantially more costly in code and cpu
  1260.    time and, given the small per-slot cost (128 bytes of memory), it seems
  1261.    reasonable to design for slot arrays at the decompressor and some
  1262.    (possibly implicit) communication of the array size.
  1263.     34. The maximum header length, fixed by the protocol design, is 64
  1264.    bytes of IP and 64 bytes of TCP.
  1265.     35. Allowing only one slot may make the compressor code more complex.
  1266.    Implementations should avoid offering one slot if possible and
  1267.    compressor implementations may disable compression if only one slot is
  1268.    negotiated.
  1269.  
  1270.  
  1271.    Jacobson                                                       [Page 19]
  1272.  
  1273.    RFC 1144               Compressing TCP/IP Headers          February 1990
  1274.  
  1275.  
  1276.        to listen that you have misconfigured your systems and are not
  1277.        interoperable.
  1278.  
  1279.  
  1280.    5.2  Choosing a maximum transmission unit
  1281.  
  1282.    From the discussion in sec. 2, it seems desirable to limit the maximum
  1283.    packet size (MTU) on any line where there might be interactive traffic
  1284.    and multiple active connections (to maintain good interactive response
  1285.    between the different connections competing for the line).  The obvious
  1286.    question is `how much does this hurt throughput?'  It doesn't.
  1287.  
  1288.    Figure 8 shows how user data throughput/36/ scales with MTU with (solid
  1289.    line) and without (dashed line) header compression.  The dotted lines
  1290.    show what MTU corresponds to a 200 ms packet time at 2400, 9600 and
  1291.    19,200 bps.  Note that with header compression even a 2400 bps line can
  1292.    be responsive yet have reasonable throughput (83%)./37/
  1293.  
  1294.    Figure 9 shows how line efficiency scales with increasing line speed,
  1295.    assuming that a 200ms. MTU is always chosen./38/  The knee in the
  1296.    performance curve is around 2400 bps.  Below this, efficiency is
  1297.    sensitive to small changes in speed (or MTU since the two are linearly
  1298.    related) and good efficiency comes at the expense of good response.
  1299.    Above 2400bps the curve is flat and efficiency is relatively independent
  1300.    of speed or MTU. In other words, it is possible to have both good
  1301.    response and high line efficiency.
  1302.  
  1303.    To illustrate, note that for a 9600 bps line with header compression
  1304.    there is essentially no benefit in increasing the MTU beyond 200 bytes:
  1305.    If the MTU is increased to 576, the average delay increases by 188%
  1306.    while throughput only improves by 3% (from 96 to 99%).
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.    ----------------------------
  1315.     36. The vertical axis is in percent of line speed.  E.g., `95' means
  1316.    that 95% of the line bandwidth is going to user data or, in other words,
  1317.    the user would see a data transfer rate of 9120 bps on a 9600 bps line.
  1318.    Four bytes of link-level (framer) encapsulation in addition to the
  1319.    TCP/IP or compressed header were included when calculating the relative
  1320.    throughput.  The 200 ms packet times were computed assuming an
  1321.    asynchronous line using 10 bits per character (8 data bits, 1 start, 1
  1322.    stop, no parity).
  1323.     37. However, the 40 byte TCP MSS required for a 2400 bps line might
  1324.    stress-test your TCP implementation.
  1325.     38. For a typical async line, a 200ms. MTU is simply .02 times the line
  1326.    speed in bits per second.
  1327.  
  1328.  
  1329.    Jacobson                                                       [Page 20]
  1330.  
  1331.    RFC 1144               Compressing TCP/IP Headers          February 1990
  1332.  
  1333.  
  1334.    5.3  Interaction with data compression
  1335.  
  1336.    Since the early 1980's, fast, effective, data compression algorithms
  1337.    such as Lempel-Ziv[7] and programs that embody them, such as the
  1338.    compress program shipped with Berkeley Unix, have become widely
  1339.    available.  When using low speed or long haul lines, it has become
  1340.    common practice to compress data before sending it.  For dialup
  1341.    connections, this compression is often done in the modems, independent
  1342.    of the communicating hosts.  Some interesting issues would seem to be:
  1343.    (1) Given a good data compressor, is there any need for header
  1344.    compression?  (2) Does header compression interact with data
  1345.    compression?  (3) Should data be compressed before or after header
  1346.    compression?/39/
  1347.  
  1348.    To investigate (1), Lempel-Ziv compression was done on a trace of 446
  1349.    TCP/IP packets taken from the user's side of a typical telnet
  1350.    conversation.  Since the packets resulted from typing, almost all
  1351.    contained only one data byte plus 40 bytes of header.  I.e., the test
  1352.    essentially measured L-Z compression of TCP/IP headers.  The compression
  1353.    ratio (the ratio of uncompressed to compressed data) was 2.6.  In other
  1354.    words, the average header was reduced from 40 to 16 bytes.  While this
  1355.    is good compression, it is far from the 5 bytes of header needed for
  1356.    good interactive response and far from the 3 bytes of header (a
  1357.    compression ratio of 13.3) that header compression yielded on the same
  1358.    packet trace.
  1359.  
  1360.    The second and third questions are more complex.  To investigate them,
  1361.    several packet traces from FTP file transfers were analyzed/40/ with and
  1362.    without header compression and with and without L-Z compression.  The
  1363.    L-Z compression was tried at two places in the outgoing data stream
  1364.    (fig. 10):    (1) just before the data was handed to TCP for
  1365.    encapsulation (simulating compression done at the `application' level)
  1366.    and (2) after the data was encapsulated (simulating compression done in
  1367.    the modem).  Table 1 summarizes the results for a 78,776 byte ASCII text
  1368.    file (the Unix csh.1 manual entry)/41/ transferred using the guidelines
  1369.    of the previous section (256 byte MTU or 216 byte MSS; 368 packets
  1370.    total).  Compression ratios for the following ten tests are shown
  1371.    (reading left to right and top to bottom):
  1372.  
  1373.    ----------------------------
  1374.     39. The answers, for those who wish to skip the remainder of this
  1375.    section, are `yes', `no' and `either', respectively.
  1376.     40. The data volume from user side of a telnet is too small to benefit
  1377.    from data compression and can be adversely affected by the delay most
  1378.    compression algorithms (necessarily) add.  The statistics and volume of
  1379.    the computer side of a telnet are similar to an (ASCII) FTP so these
  1380.    results should apply to either.
  1381.     41. The ten experiments described were each done on ten ASCII files
  1382.    (four long e-mail messages, three Unix C source files and three Unix
  1383.    manual entries).  The results were remarkably similar for different
  1384.    files and the general conclusions reached below apply to all ten files.
  1385.  
  1386.  
  1387.    Jacobson                                                       [Page 21]
  1388.  
  1389.    RFC 1144               Compressing TCP/IP Headers          February 1990
  1390.  
  1391.  
  1392.      - data file (no compression or encapsulation)
  1393.  
  1394.      - data -> L--Z compressor
  1395.  
  1396.      - data -> TCP/IP encapsulation
  1397.  
  1398.      - data -> L--Z -> TCP/IP
  1399.  
  1400.      - data -> TCP/IP -> L--Z
  1401.  
  1402.      - data -> L--Z -> TCP/IP -> L--Z
  1403.  
  1404.      - data -> TCP/IP -> Hdr. Compress.
  1405.  
  1406.      - data -> L--Z -> TCP/IP -> Hdr. Compress.
  1407.  
  1408.      - data -> TCP/IP -> Hdr. Compress. -> L--Z
  1409.  
  1410.      - data -> L--Z -> TCP/IP -> Hdr. Compress. -> L--Z
  1411.  
  1412.  
  1413.             +-----------------------------------------------------+
  1414.             |              | No data  | L--Z   |  L--Z  |  L--Z   |
  1415.             |              |compress. |on data |on wire | on both |
  1416.             +--------------+----------+--------+--------+---------+
  1417.             | Raw Data     |     1.00 |   2.44 |   ---- |    ---- |
  1418.             | + TCP Encap. |     0.83 |   2.03 |   1.97 |    1.58 |
  1419.             | w/Hdr Comp.  |     0.98 |   2.39 |   2.26 |    1.66 |
  1420.             +-----------------------------------------------------+
  1421.  
  1422.                  Table 1:  ASCII Text File Compression Ratios
  1423.  
  1424.  
  1425.    The first column of table 1 says the data expands by 19% (`compresses'
  1426.    by .83) when encapsulated in TCP/IP and by 2% when encapsulated in
  1427.    header compressed TCP/IP./42/ The first row says L--Z compression is
  1428.    quite effective on this data, shrinking it to less than half its
  1429.    original size.  Column four illustrates the well-known fact that it is a
  1430.    mistake to L--Z compress already compressed data.  The interesting
  1431.    information is in rows two and three of columns two and three.  These
  1432.    columns say that the benefit of data compression overwhelms the cost of
  1433.    encapsulation, even for straight TCP/IP. They also say that it is
  1434.    slightly better to compress the data before encapsulating it rather than
  1435.    compressing at the framing/modem level.  The differences however are
  1436.  
  1437.  
  1438.  
  1439.  
  1440.    ----------------------------
  1441.     42. This is what would be expected from the relative header sizes:
  1442.    256/216 for TCP/IP and 219/216 for header compression.
  1443.  
  1444.  
  1445.    Jacobson                                                       [Page 22]
  1446.  
  1447.    RFC 1144               Compressing TCP/IP Headers          February 1990
  1448.  
  1449.  
  1450.    small --- 3% and 6%, respectively, for the TCP/IP and header compressed
  1451.    encapsulations./43/
  1452.  
  1453.    Table 2 shows the same experiment for a 122,880 byte binary file (the
  1454.    Sun-3 ps executable).  Although the raw data doesn't compress nearly as
  1455.    well, the results are qualitatively the same as for the ASCII data.  The
  1456.    one significant change is in row two:  It is about 3% better to compress
  1457.    the data in the modem rather than at the source if doing TCP/IP
  1458.    encapsulation (apparently, Sun binaries and TCP/IP headers have similar
  1459.    statistics).  However, with header compression (row three) the results
  1460.    were similar to the ASCII data --- it's about 3% worse to compress at
  1461.    the modem rather than the source./44/
  1462.  
  1463.  
  1464.             +-----------------------------------------------------+
  1465.             |              | No data  | L--Z   |  L--Z  |  L--Z   |
  1466.             |              |compress. |on data |on wire | on both |
  1467.             +--------------+----------+--------+--------+---------+
  1468.             | Raw Data     |     1.00 |   1.72 |   ---- |    ---- |
  1469.             | + TCP Encap. |     0.83 |   1.43 |   1.48 |    1.21 |
  1470.             | w/Hdr Comp.  |     0.98 |   1.69 |   1.64 |    1.28 |
  1471.             +-----------------------------------------------------+
  1472.  
  1473.                    Table 2:  Binary File Compression Ratios
  1474.  
  1475.  
  1476.  
  1477.  
  1478.    6  Performance measurements
  1479.  
  1480.  
  1481.    An implementation goal of compression code was to arrive at something
  1482.    simple enough to run at ISDN speeds (64Kbps) on a typical 1989
  1483.  
  1484.  
  1485.  
  1486.    ----------------------------
  1487.     43. The differences are due to the wildly different byte patterns of
  1488.    TCP/IP datagrams and ASCII text.  Any compression scheme with an
  1489.    underlying, Markov source model, such as Lempel-Ziv, will do worse when
  1490.    radically different sources are interleaved.  If the relative
  1491.    proportions of the two sources are changed, i.e., the MTU is increased,
  1492.    the performance difference between the two compressor locations
  1493.    decreases.  However, the rate of decrease is very slow --- increasing
  1494.    the MTU by 400% (256 to 1024) only changed the difference between the
  1495.    data and modem L--Z choices from 2.5% to 1.3%.
  1496.     44. There are other good reasons to compress at the source:  Far fewer
  1497.    packets have to be encapsulated and far fewer characters have to be sent
  1498.    to the modem.  The author suspects that the `compress data in the modem'
  1499.    alternative should be avoided except when faced with an intractable,
  1500.    vendor proprietary operating system.
  1501.  
  1502.  
  1503.    Jacobson                                                       [Page 23]
  1504.  
  1505.    RFC 1144               Compressing TCP/IP Headers          February 1990
  1506.  
  1507.  
  1508.  
  1509.                    +---------------------------------------+
  1510.                    |               |  Average per-packet   |
  1511.                    |    Machine    | processing time (us.) |
  1512.                    |               |                       |
  1513.                    |               | Compress | Decompress |
  1514.                    +---------------+----------+------------+
  1515.                    |Sparcstation-1 |       24 |         18 |
  1516.                    |   Sun 4/260   |       46 |         20 |
  1517.                    |   Sun 3/60    |       90 |         90 |
  1518.                    |   Sun 3/50    |      130 |        150 |
  1519.                    |  HP9000/370   |       42 |         33 |
  1520.                    |  HP9000/360   |       68 |         70 |
  1521.                    |   DEC 3100    |       27 |         25 |
  1522.                    |    Vax 780    |      430 |        300 |
  1523.                    |    Vax 750    |      800 |        500 |
  1524.                    |   CCI Tahoe   |      110 |        140 |
  1525.                    +---------------------------------------+
  1526.  
  1527.                       Table 3:  Compression code timings
  1528.  
  1529.  
  1530.    workstation.  64Kbps is a byte every 122us so 120us was (arbitrarily)
  1531.    picked as the target compression/decompression time./45/
  1532.  
  1533.    As part of the compression code development, a trace-driven exerciser
  1534.    was developed.  This was initially used to compare different compression
  1535.    protocol choices then later to test the code on different computer
  1536.    architectures and do regression tests after performance `improvements'.
  1537.    A small modification of this test program resulted in a useful
  1538.    measurement tool./46/  Table 3 shows the result of timing the
  1539.    compression code on all the machines available to the author (times were
  1540.    measured using a mixed telnet/ftp traffic trace).  With the exception of
  1541.    the Vax architectures, which suffer from (a) having bytes in the wrong
  1542.    order and (b) a lousy compiler (Unix pcc), all machines essentially met
  1543.    the 120us goal.
  1544.  
  1545.  
  1546.  
  1547.  
  1548.    ----------------------------
  1549.     45. The time choice wasn't completely arbitrary:  Decompression is
  1550.    often done during the inter-frame `flag' character time so, on systems
  1551.    where the decompression is done at the same priority level as the serial
  1552.    line input interrupt, times much longer than a character time would
  1553.    result in receiver overruns.  And, with the current average of five byte
  1554.    frames (on the wire, including both compressed header and framing), a
  1555.    compression/decompression that takes one byte time can use at most 20%
  1556.    of the available time.  This seems like a comfortable budget.
  1557.     46. Both the test program and timer program are included in the
  1558.    ftp-able package described in appendix A as files tester.c and timer.c.
  1559.  
  1560.  
  1561.    Jacobson                                                       [Page 24]
  1562.  
  1563.    RFC 1144               Compressing TCP/IP Headers          February 1990
  1564.  
  1565.  
  1566.    7  Acknowlegements
  1567.  
  1568.  
  1569.    The author is grateful to the members of the Internet Engineering Task
  1570.    Force, chaired by Phill Gross, who provided encouragement and thoughtful
  1571.    review of this work.  Several patient beta-testers, particularly Sam
  1572.    Leffler and Craig Leres, tracked down and fixed problems in the initial
  1573.    implementation.  Cynthia Livingston and Craig Partridge carefully read
  1574.    and greatly improved an unending sequence of partial drafts of this
  1575.    document.  And last but not least, Telebit modem corporation,
  1576.    particularly Mike Ballard, encouraged this work from its inception and
  1577.    has been an ongoing champion of serial line and dial-up IP.
  1578.  
  1579.  
  1580.    References
  1581.  
  1582.     [1] Bingham, J. A. C. Theory and Practice of Modem Design. John Wiley
  1583.         & Sons, 1988.
  1584.  
  1585.     [2] Carey, M. B., Chan, H.-T., Descloux, A., Ingle, J. F., and Park,
  1586.         K. I. 1982/83 end office connection study:  Analog voice and
  1587.         voiceband data transmission performance characterization of the
  1588.         public switched network. Bell System Technical Journal 63, 9 (Nov.
  1589.         1984).
  1590.  
  1591.     [3] Chiappa, N., 1988. Private communication.
  1592.  
  1593.     [4] Clark, D. D. The design philosophy of the DARPA Internet
  1594.         protocols. In Proceedings of SIGCOMM '88 (Stanford, CA, Aug.
  1595.         1988), ACM.
  1596.  
  1597.     [5] Farber, D. J., Delp, G. S., and Conte, T. M. A Thinwire Protocol
  1598.         for connecting personal computers to the Internet. Arpanet Working
  1599.         Group Requests for Comment, DDN Network Information Center, SRI
  1600.         International, Menlo Park, CA, Sept. 1984. RFC-914.
  1601.  
  1602.     [6] Kent, C. A., and Mogul, J. Fragmentation considered harmful. In
  1603.         Proceedings of SIGCOMM '87 (Aug. 1987), ACM.
  1604.  
  1605.     [7] Lempel, A., and Ziv, J. Compression of individual sequences via
  1606.         variable-rate encoding. IEEE Transactions on Information Theory
  1607.         IT-24, 5 (June 1978).
  1608.  
  1609.     [8] Nagle, J. Congestion Control in IP/TCP Internetworks. Arpanet
  1610.         Working Group Requests for Comment, DDN Network Information Center,
  1611.         SRI International, Menlo Park, CA, Jan. 1984. RFC-896.
  1612.  
  1613.     [9] Perkins, D. Point-to-Point Protocol:  A proposal for
  1614.         multi-protocol transmission of datagrams over point-to-point links.
  1615.         Arpanet Working Group Requests for Comment, DDN Network Information
  1616.         Center, SRI International, Menlo Park, CA, Nov. 1989. RFC-1134.
  1617.  
  1618.  
  1619.    Jacobson                                                       [Page 25]
  1620.  
  1621.    RFC 1144               Compressing TCP/IP Headers          February 1990
  1622.  
  1623.  
  1624.    [10] Postel, J., Ed. Internet Protocol Specification. SRI
  1625.         International, Menlo Park, CA, Sept. 1981. RFC-791.
  1626.  
  1627.    [11] Postel, J., Ed. Transmission Control Protocol Specification. SRI
  1628.         International, Menlo Park, CA, Sept. 1981. RFC-793.
  1629.  
  1630.    [12] Romkey, J. A Nonstandard for Transmission of IP Datagrams Over
  1631.         Serial Lines:  Slip. Arpanet Working Group Requests for Comment,
  1632.         DDN Network Information Center, SRI International, Menlo Park, CA,
  1633.         June 1988. RFC-1055.
  1634.  
  1635.    [13] Salthouse, T. A. The skill of typing. Scientific American 250, 2
  1636.         (Feb. 1984), 128--135.
  1637.  
  1638.    [14] Saltzer, J. H., Reed, D. P., and Clark, D. D. End-to-end arguments
  1639.         in system design. ACM Transactions on Computer Systems 2, 4 (Nov.
  1640.         1984).
  1641.  
  1642.    [15] Shneiderman, B. Designing the User Interface. Addison-Wesley,
  1643.         1987.
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  
  1657.  
  1658.  
  1659.  
  1660.  
  1661.  
  1662.  
  1663.  
  1664.  
  1665.  
  1666.  
  1667.  
  1668.  
  1669.  
  1670.  
  1671.  
  1672.  
  1673.  
  1674.  
  1675.  
  1676.  
  1677.    Jacobson                                                       [Page 26]
  1678.  
  1679.    RFC 1144               Compressing TCP/IP Headers          February 1990
  1680.  
  1681.  
  1682.    A  Sample Implementation
  1683.  
  1684.  
  1685.    The following is a sample implementation of the protocol described in
  1686.    this document.
  1687.  
  1688.    Since many people who might have the deal with this code are familiar
  1689.    with the Berkeley Unix kernel and its coding style (affectionately known
  1690.    as kernel normal form), this code was done in that style.  It uses the
  1691.    Berkeley `subroutines' (actually, macros and/or inline assembler
  1692.    expansions) for converting to/from network byte order and
  1693.    copying/comparing strings of bytes.  These routines are briefly
  1694.    described in sec. A.5 for anyone not familiar with them.
  1695.  
  1696.    This code has been run on all the machines listed in the table on page
  1697.    24.  Thus, the author hopes there are no byte order or alignment
  1698.    problems (although there are embedded assumptions about alignment that
  1699.    are valid for Berkeley Unix but may not be true for other IP
  1700.    implementations --- see the comments mentioning alignment in
  1701.    sl_compress_tcp and sl_decompress_tcp).
  1702.  
  1703.    There was some attempt to make this code efficient.  Unfortunately, that
  1704.    may have made portions of it incomprehensible.  The author apologizes
  1705.    for any frustration this engenders.  (In honesty, my C style is known to
  1706.    be obscure and claims of `efficiency' are simply a convenient excuse.)
  1707.  
  1708.    This sample code and a complete Berkeley Unix implementation is
  1709.    available in machine readable form via anonymous ftp from Internet host
  1710.    ftp.ee.lbl.gov (128.3.254.68), file cslip.tar.Z. This is a compressed
  1711.    Unix tar file.  It must be ftped in binary mode.
  1712.  
  1713.    All of the code in this appendix is covered by the following copyright:
  1714.  
  1715.    /*
  1716.     * Copyright (c) 1989 Regents of the University of California.
  1717.     * All rights reserved.
  1718.     *
  1719.     * Redistribution and use in source and binary forms are
  1720.     * permitted provided that the above copyright notice and this
  1721.     * paragraph are duplicated in all such forms and that any
  1722.     * documentation, advertising materials, and other materials
  1723.     * related to such distribution and use acknowledge that the
  1724.     * software was developed by the University of California,
  1725.     * Berkeley.  The name of the University may not be used to
  1726.     * endorse or promote products derived from this software
  1727.     * without specific prior written permission.
  1728.     * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS
  1729.     * OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE
  1730.     * IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A
  1731.     * PARTICULAR PURPOSE.
  1732.     */
  1733.  
  1734.  
  1735.    Jacobson                                                       [Page 27]
  1736.  
  1737.    RFC 1144               Compressing TCP/IP Headers          February 1990
  1738.  
  1739.  
  1740.    A.1  Definitions and State Data
  1741.  
  1742.    #define MAX_STATES 16   /* must be >2 and <255 */
  1743.    #define MAX_HDR 128     /* max TCP+IP hdr length (by protocol def) */
  1744.  
  1745.    /* packet types */
  1746.    #define TYPE_IP 0x40
  1747.    #define TYPE_UNCOMPRESSED_TCP 0x70
  1748.    #define TYPE_COMPRESSED_TCP 0x80
  1749.    #define TYPE_ERROR 0x00 /* this is not a type that ever appears on
  1750.                             * the wire.  The receive framer uses it to
  1751.                             * tell the decompressor there was a packet
  1752.                             * transmission error. */
  1753.    /*
  1754.     * Bits in first octet of compressed packet
  1755.     */
  1756.  
  1757.    /* flag bits for what changed in a packet */
  1758.  
  1759.    #define NEW_C  0x40
  1760.    #define NEW_I  0x20
  1761.    #define TCP_PUSH_BIT 0x10
  1762.  
  1763.    #define NEW_S  0x08
  1764.    #define NEW_A  0x04
  1765.    #define NEW_W  0x02
  1766.    #define NEW_U  0x01
  1767.  
  1768.    /* reserved, special-case values of above */
  1769.    #define SPECIAL_I (NEW_S|NEW_W|NEW_U)        /* echoed interactive traffic */
  1770.    #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)  /* unidirectional data */
  1771.    #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
  1772.  
  1773.  
  1774.    /*
  1775.     * "state" data for each active tcp conversation on the wire.  This is
  1776.     * basically a copy of the entire IP/TCP header from the last packet together
  1777.     * with a small identifier the transmit & receive ends of the line use to
  1778.     * locate saved header.
  1779.     */
  1780.    struct cstate {
  1781.         struct cstate *cs_next;  /* next most recently used cstate (xmit only) */
  1782.         u_short cs_hlen;         /* size of hdr (receive only) */
  1783.         u_char cs_id;            /* connection # associated with this state */
  1784.         u_char cs_filler;
  1785.         union {
  1786.              char hdr[MAX_HDR];
  1787.              struct ip csu_ip;   /* ip/tcp hdr from most recent packet */
  1788.         } slcs_u;
  1789.    };
  1790.    #define cs_ip slcs_u.csu_ip
  1791.  
  1792.  
  1793.    Jacobson                                                       [Page 28]
  1794.  
  1795.    RFC 1144               Compressing TCP/IP Headers          February 1990
  1796.  
  1797.  
  1798.    #define cs_hdr slcs_u.csu_hdr
  1799.  
  1800.    /*
  1801.     * all the state data for one serial line (we need one of these per line).
  1802.     */
  1803.    struct slcompress {
  1804.         struct cstate *last_cs;            /* most recently used tstate */
  1805.         u_char last_recv;                  /* last rcvd conn. id */
  1806.         u_char last_xmit;                  /* last sent conn. id */
  1807.         u_short flags;
  1808.         struct cstate tstate[MAX_STATES];  /* xmit connection states */
  1809.         struct cstate rstate[MAX_STATES];  /* receive connection states */
  1810.    };
  1811.  
  1812.    /* flag values */
  1813.    #define SLF_TOSS 1       /* tossing rcvd frames because of input err */
  1814.  
  1815.    /*
  1816.     * The following macros are used to encode and decode numbers.  They all
  1817.     * assume that `cp' points to a buffer where the next byte encoded (decoded)
  1818.     * is to be stored (retrieved).  Since the decode routines do arithmetic,
  1819.     * they have to convert from and to network byte order.
  1820.     */
  1821.  
  1822.    /*
  1823.     * ENCODE encodes a number that is known to be non-zero.  ENCODEZ checks for
  1824.     * zero (zero has to be encoded in the long, 3 byte form).
  1825.     */
  1826.    #define ENCODE(n) { \
  1827.         if ((u_short)(n) >= 256) { \
  1828.              *cp++ = 0; \
  1829.              cp[1] = (n); \
  1830.              cp[0] = (n) >> 8; \
  1831.              cp += 2; \
  1832.         } else { \
  1833.              *cp++ = (n); \
  1834.         } \
  1835.    }
  1836.    #define ENCODEZ(n) { \
  1837.         if ((u_short)(n) >= 256 || (u_short)(n) == 0) { \
  1838.              *cp++ = 0; \
  1839.              cp[1] = (n); \
  1840.              cp[0] = (n) >> 8; \
  1841.              cp += 2; \
  1842.         } else { \
  1843.              *cp++ = (n); \
  1844.         } \
  1845.    }
  1846.  
  1847.    /*
  1848.     * DECODEL takes the (compressed) change at byte cp and adds it to the
  1849.  
  1850.  
  1851.    Jacobson                                                       [Page 29]
  1852.  
  1853.    RFC 1144               Compressing TCP/IP Headers          February 1990
  1854.  
  1855.  
  1856.     * current value of packet field 'f' (which must be a 4-byte (long) integer
  1857.     * in network byte order).  DECODES does the same for a 2-byte (short) field.
  1858.     * DECODEU takes the change at cp and stuffs it into the (short) field f.
  1859.     * 'cp' is updated to point to the next field in the compressed header.
  1860.     */
  1861.    #define DECODEL(f) { \
  1862.         if (*cp == 0) {\
  1863.              (f) = htonl(ntohl(f) + ((cp[1] << 8) | cp[2])); \
  1864.              cp += 3; \
  1865.         } else { \
  1866.              (f) = htonl(ntohl(f) + (u_long)*cp++); \
  1867.         } \
  1868.    }
  1869.    #define DECODES(f) { \
  1870.         if (*cp == 0) {\
  1871.              (f) = htons(ntohs(f) + ((cp[1] << 8) | cp[2])); \
  1872.              cp += 3; \
  1873.         } else { \
  1874.              (f) = htons(ntohs(f) + (u_long)*cp++); \
  1875.         } \
  1876.    }
  1877.    #define DECODEU(f) { \
  1878.         if (*cp == 0) {\
  1879.              (f) = htons((cp[1] << 8) | cp[2]); \
  1880.              cp += 3; \
  1881.         } else { \
  1882.              (f) = htons((u_long)*cp++); \
  1883.         } \
  1884.    }
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.    Jacobson                                                       [Page 30]
  1910.  
  1911.    RFC 1144               Compressing TCP/IP Headers          February 1990
  1912.  
  1913.  
  1914.    A.2  Compression
  1915.  
  1916.    This routine looks daunting but isn't really.  The code splits into four
  1917.    approximately equal sized sections:  The first quarter manages a
  1918.    circularly linked, least-recently-used list of `active' TCP
  1919.    connections./47/  The second figures out the sequence/ack/window/urg
  1920.    changes and builds the bulk of the compressed packet.  The third handles
  1921.    the special-case encodings.  The last quarter does packet ID and
  1922.    connection ID encoding and replaces the original packet header with the
  1923.    compressed header.
  1924.  
  1925.    The arguments to this routine are a pointer to a packet to be
  1926.    compressed, a pointer to the compression state data for the serial line,
  1927.    and a flag which enables or disables connection id (C bit) compression.
  1928.  
  1929.    Compression is done `in-place' so, if a compressed packet is created,
  1930.    both the start address and length of the incoming packet (the off and
  1931.    len fields of m) will be updated to reflect the removal of the original
  1932.    header and its replacement by the compressed header.  If either a
  1933.    compressed or uncompressed packet is created, the compression state is
  1934.    updated.  This routines returns the packet type for the transmit framer
  1935.    (TYPE_IP, TYPE_UNCOMPRESSED_TCP or TYPE_COMPRESSED_TCP).
  1936.  
  1937.    Because 16 and 32 bit arithmetic is done on various header fields, the
  1938.    incoming IP packet must be aligned appropriately (e.g., on a SPARC, the
  1939.    IP header is aligned on a 32-bit boundary).  Substantial changes would
  1940.    have to be made to the code below if this were not true (and it would
  1941.    probably be cheaper to byte copy the incoming header to somewhere
  1942.    correctly aligned than to make those changes).
  1943.  
  1944.    Note that the outgoing packet will be aligned arbitrarily (e.g., it
  1945.    could easily start on an odd-byte boundary).
  1946.  
  1947.    u_char
  1948.    sl_compress_tcp(m, comp, compress_cid)
  1949.         struct mbuf *m;
  1950.         struct slcompress *comp;
  1951.         int compress_cid;
  1952.    {
  1953.         register struct cstate *cs = comp->last_cs->cs_next;
  1954.         register struct ip *ip = mtod(m, struct ip *);
  1955.         register u_int hlen = ip->ip_hl;
  1956.         register struct tcphdr *oth;       /* last TCP header */
  1957.         register struct tcphdr *th;        /* current TCP header */
  1958.  
  1959.    ----------------------------
  1960.     47. The two most common operations on the connection list are a `find'
  1961.    that terminates at the first entry (a new packet for the most recently
  1962.    used connection) and moving the last entry on the list to the head of
  1963.    the list (the first packet from a new connection).  A circular list
  1964.    efficiently handles these two operations.
  1965.  
  1966.  
  1967.    Jacobson                                                       [Page 31]
  1968.  
  1969.    RFC 1144               Compressing TCP/IP Headers          February 1990
  1970.  
  1971.  
  1972.         register u_int deltaS, deltaA;     /* general purpose temporaries */
  1973.         register u_int changes = 0;        /* change mask */
  1974.         u_char new_seq[16];                /* changes from last to current */
  1975.         register u_char *cp = new_seq;
  1976.  
  1977.         /*
  1978.          * Bail if this is an IP fragment or if the TCP packet isn't
  1979.          * `compressible' (i.e., ACK isn't set or some other control bit is
  1980.          * set).  (We assume that the caller has already made sure the packet
  1981.          * is IP proto TCP).
  1982.          */
  1983.         if ((ip->ip_off & htons(0x3fff)) || m->m_len < 40)
  1984.              return (TYPE_IP);
  1985.  
  1986.         th = (struct tcphdr *) & ((int *) ip)[hlen];
  1987.         if ((th->th_flags & (TH_SYN | TH_FIN | TH_RST | TH_ACK)) != TH_ACK)
  1988.              return (TYPE_IP);
  1989.  
  1990.         /*
  1991.          * Packet is compressible -- we're going to send either a
  1992.          * COMPRESSED_TCP or UNCOMPRESSED_TCP packet.  Either way we need to
  1993.          * locate (or create) the connection state.  Special case the most
  1994.          * recently used connection since it's most likely to be used again &
  1995.          * we don't have to do any reordering if it's used.
  1996.          */
  1997.         if (ip->ip_src.s_addr != cs->cs_ip.ip_src.s_addr ||
  1998.             ip->ip_dst.s_addr != cs->cs_ip.ip_dst.s_addr ||
  1999.             *(int *) th != ((int *) &cs->cs_ip)[cs->cs_ip.ip_hl]) {
  2000.  
  2001.              /*
  2002.               * Wasn't the first -- search for it.
  2003.               *
  2004.               * States are kept in a circularly linked list with last_cs
  2005.               * pointing to the end of the list.  The list is kept in lru
  2006.               * order by moving a state to the head of the list whenever
  2007.               * it is referenced.  Since the list is short and,
  2008.               * empirically, the connection we want is almost always near
  2009.               * the front, we locate states via linear search.  If we
  2010.               * don't find a state for the datagram, the oldest state is
  2011.               * (re-)used.
  2012.               */
  2013.              register struct cstate *lcs;
  2014.              register struct cstate *lastcs = comp->last_cs;
  2015.  
  2016.              do {
  2017.                   lcs = cs;
  2018.                   cs = cs->cs_next;
  2019.                   if (ip->ip_src.s_addr == cs->cs_ip.ip_src.s_addr
  2020.                       && ip->ip_dst.s_addr == cs->cs_ip.ip_dst.s_addr
  2021.                       && *(int *) th == ((int *) &cs->cs_ip)[cs->cs_ip.ip_hl])
  2022.                        goto found;
  2023.  
  2024.  
  2025.    Jacobson                                                       [Page 32]
  2026.  
  2027.    RFC 1144               Compressing TCP/IP Headers          February 1990
  2028.  
  2029.  
  2030.              } while (cs != lastcs);
  2031.  
  2032.              /*
  2033.               * Didn't find it -- re-use oldest cstate.  Send an
  2034.               * uncompressed packet that tells the other side what
  2035.               * connection number we're using for this conversation. Note
  2036.               * that since the state list is circular, the oldest state
  2037.               * points to the newest and we only need to set last_cs to
  2038.               * update the lru linkage.
  2039.               */
  2040.              comp->last_cs = lcs;
  2041.              hlen += th->th_off;
  2042.              hlen <<= 2;
  2043.              goto uncompressed;
  2044.  
  2045.    found:
  2046.              /* Found it -- move to the front on the connection list. */
  2047.              if (lastcs == cs)
  2048.                   comp->last_cs = lcs;
  2049.              else {
  2050.                   lcs->cs_next = cs->cs_next;
  2051.                   cs->cs_next = lastcs->cs_next;
  2052.                   lastcs->cs_next = cs;
  2053.              }
  2054.         }
  2055.         /*
  2056.          * Make sure that only what we expect to change changed. The first
  2057.          * line of the `if' checks the IP protocol version, header length &
  2058.          * type of service.  The 2nd line checks the "Don't fragment" bit.
  2059.          * The 3rd line checks the time-to-live and protocol (the protocol
  2060.          * check is unnecessary but costless).  The 4th line checks the TCP
  2061.          * header length.  The 5th line checks IP options, if any.  The 6th
  2062.          * line checks TCP options, if any.  If any of these things are
  2063.          * different between the previous & current datagram, we send the
  2064.          * current datagram `uncompressed'.
  2065.          */
  2066.         oth = (struct tcphdr *) & ((int *) &cs->cs_ip)[hlen];
  2067.         deltaS = hlen;
  2068.         hlen += th->th_off;
  2069.         hlen <<= 2;
  2070.  
  2071.         if (((u_short *) ip)[0] != ((u_short *) &cs->cs_ip)[0] ||
  2072.             ((u_short *) ip)[3] != ((u_short *) &cs->cs_ip)[3] ||
  2073.             ((u_short *) ip)[4] != ((u_short *) &cs->cs_ip)[4] ||
  2074.             th->th_off != oth->th_off ||
  2075.             (deltaS > 5 && BCMP(ip + 1, &cs->cs_ip + 1, (deltaS - 5) << 2)) ||
  2076.             (th->th_off > 5 && BCMP(th + 1, oth + 1, (th->th_off - 5) << 2)))
  2077.              goto uncompressed;
  2078.  
  2079.         /*
  2080.          * Figure out which of the changing fields changed.  The receiver
  2081.  
  2082.  
  2083.    Jacobson                                                       [Page 33]
  2084.  
  2085.    RFC 1144               Compressing TCP/IP Headers          February 1990
  2086.  
  2087.  
  2088.          * expects changes in the order: urgent, window, ack, seq.
  2089.          */
  2090.         if (th->th_flags & TH_URG) {
  2091.              deltaS = ntohs(th->th_urp);
  2092.              ENCODEZ(deltaS);
  2093.              changes |= NEW_U;
  2094.         } else if (th->th_urp != oth->th_urp)
  2095.              /*
  2096.               * argh! URG not set but urp changed -- a sensible
  2097.               * implementation should never do this but RFC793 doesn't
  2098.               * prohibit the change so we have to deal with it.
  2099.               */
  2100.              goto uncompressed;
  2101.  
  2102.         if (deltaS = (u_short) (ntohs(th->th_win) - ntohs(oth->th_win))) {
  2103.              ENCODE(deltaS);
  2104.              changes |= NEW_W;
  2105.         }
  2106.         if (deltaA = ntohl(th->th_ack) - ntohl(oth->th_ack)) {
  2107.              if (deltaA > 0xffff)
  2108.                   goto uncompressed;
  2109.              ENCODE(deltaA);
  2110.              changes |= NEW_A;
  2111.         }
  2112.         if (deltaS = ntohl(th->th_seq) - ntohl(oth->th_seq)) {
  2113.              if (deltaS > 0xffff)
  2114.                   goto uncompressed;
  2115.              ENCODE(deltaS);
  2116.              changes |= NEW_S;
  2117.         }
  2118.         /*
  2119.          * Look for the special-case encodings.
  2120.          */
  2121.         switch (changes) {
  2122.  
  2123.         case 0:
  2124.              /*
  2125.               * Nothing changed. If this packet contains data and the last
  2126.               * one didn't, this is probably a data packet following an
  2127.               * ack (normal on an interactive connection) and we send it
  2128.               * compressed.  Otherwise it's probably a retransmit,
  2129.               * retransmitted ack or window probe.  Send it uncompressed
  2130.               * in case the other side missed the compressed version.
  2131.               */
  2132.              if (ip->ip_len != cs->cs_ip.ip_len &&
  2133.                  ntohs(cs->cs_ip.ip_len) == hlen)
  2134.                   break;
  2135.  
  2136.              /* (fall through) */
  2137.  
  2138.         case SPECIAL_I:
  2139.  
  2140.  
  2141.    Jacobson                                                       [Page 34]
  2142.  
  2143.    RFC 1144               Compressing TCP/IP Headers          February 1990
  2144.  
  2145.  
  2146.         case SPECIAL_D:
  2147.              /*
  2148.               * Actual changes match one of our special case encodings --
  2149.               * send packet uncompressed.
  2150.               */
  2151.              goto uncompressed;
  2152.  
  2153.         case NEW_S | NEW_A:
  2154.              if (deltaS == deltaA &&
  2155.                  deltaS == ntohs(cs->cs_ip.ip_len) - hlen) {
  2156.                   /* special case for echoed terminal traffic */
  2157.                   changes = SPECIAL_I;
  2158.                   cp = new_seq;
  2159.              }
  2160.              break;
  2161.  
  2162.         case NEW_S:
  2163.              if (deltaS == ntohs(cs->cs_ip.ip_len) - hlen) {
  2164.                   /* special case for data xfer */
  2165.                   changes = SPECIAL_D;
  2166.                   cp = new_seq;
  2167.              }
  2168.              break;
  2169.         }
  2170.         deltaS = ntohs(ip->ip_id) - ntohs(cs->cs_ip.ip_id);
  2171.         if (deltaS != 1) {
  2172.              ENCODEZ(deltaS);
  2173.              changes |= NEW_I;
  2174.         }
  2175.         if (th->th_flags & TH_PUSH)
  2176.              changes |= TCP_PUSH_BIT;
  2177.         /*
  2178.          * Grab the cksum before we overwrite it below.  Then update our
  2179.          * state with this packet's header.
  2180.          */
  2181.         deltaA = ntohs(th->th_sum);
  2182.         BCOPY(ip, &cs->cs_ip, hlen);
  2183.  
  2184.         /*
  2185.          * We want to use the original packet as our compressed packet. (cp -
  2186.          * new_seq) is the number of bytes we need for compressed sequence
  2187.          * numbers.  In addition we need one byte for the change mask, one
  2188.          * for the connection id and two for the tcp checksum. So, (cp -
  2189.          * new_seq) + 4 bytes of header are needed.  hlen is how many bytes
  2190.          * of the original packet to toss so subtract the two to get the new
  2191.          * packet size.
  2192.          */
  2193.         deltaS = cp - new_seq;
  2194.         cp = (u_char *) ip;
  2195.         if (compress_cid == 0 || comp->last_xmit != cs->cs_id) {
  2196.              comp->last_xmit = cs->cs_id;
  2197.  
  2198.  
  2199.    Jacobson                                                       [Page 35]
  2200.  
  2201.    RFC 1144               Compressing TCP/IP Headers          February 1990
  2202.  
  2203.  
  2204.              hlen -= deltaS + 4;
  2205.              cp += hlen;
  2206.              *cp++ = changes | NEW_C;
  2207.              *cp++ = cs->cs_id;
  2208.         } else {
  2209.              hlen -= deltaS + 3;
  2210.              cp += hlen;
  2211.              *cp++ = changes;
  2212.         }
  2213.         m->m_len -= hlen;
  2214.         m->m_off += hlen;
  2215.         *cp++ = deltaA >> 8;
  2216.         *cp++ = deltaA;
  2217.         BCOPY(new_seq, cp, deltaS);
  2218.         return (TYPE_COMPRESSED_TCP);
  2219.  
  2220.    uncompressed:
  2221.         /*
  2222.          * Update connection state cs & send uncompressed packet
  2223.          * ('uncompressed' means a regular ip/tcp packet but with the
  2224.          * 'conversation id' we hope to use on future compressed packets in
  2225.          * the protocol field).
  2226.          */
  2227.         BCOPY(ip, &cs->cs_ip, hlen);
  2228.         ip->ip_p = cs->cs_id;
  2229.         comp->last_xmit = cs->cs_id;
  2230.         return (TYPE_UNCOMPRESSED_TCP);
  2231.    }
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  
  2249.  
  2250.  
  2251.  
  2252.  
  2253.  
  2254.  
  2255.  
  2256.  
  2257.    Jacobson                                                       [Page 36]
  2258.  
  2259.    RFC 1144               Compressing TCP/IP Headers          February 1990
  2260.  
  2261.  
  2262.    A.3  Decompression
  2263.  
  2264.    This routine decompresses a received packet.  It is called with a
  2265.    pointer to the packet, the packet length and type, and a pointer to the
  2266.    compression state structure for the incoming serial line.  It returns a
  2267.    pointer to the resulting packet or zero if there were errors in the
  2268.    incoming packet.  If the packet is COMPRESSED_TCP or UNCOMPRESSED_TCP,
  2269.    the compression state will be updated.
  2270.  
  2271.    The new packet will be constructed in-place.  That means that there must
  2272.    be 128 bytes of free space in front of bufp to allow room for the
  2273.    reconstructed IP and TCP headers.  The reconstructed packet will be
  2274.    aligned on a 32-bit boundary.
  2275.  
  2276.    u_char *
  2277.    sl_uncompress_tcp(bufp, len, type, comp)
  2278.         u_char *bufp;
  2279.         int len;
  2280.         u_int type;
  2281.         struct slcompress *comp;
  2282.    {
  2283.         register u_char *cp;
  2284.         register u_int hlen, changes;
  2285.         register struct tcphdr *th;
  2286.         register struct cstate *cs;
  2287.         register struct ip *ip;
  2288.  
  2289.         switch (type) {
  2290.  
  2291.         case TYPE_ERROR:
  2292.         default:
  2293.              goto bad;
  2294.  
  2295.         case TYPE_IP:
  2296.              return (bufp);
  2297.  
  2298.         case TYPE_UNCOMPRESSED_TCP:
  2299.              /*
  2300.               * Locate the saved state for this connection.  If the state
  2301.               * index is legal, clear the 'discard' flag.
  2302.               */
  2303.              ip = (struct ip *) bufp;
  2304.              if (ip->ip_p >= MAX_STATES)
  2305.                   goto bad;
  2306.  
  2307.              cs = &comp->rstate[comp->last_recv = ip->ip_p];
  2308.              comp->flags &= ~SLF_TOSS;
  2309.              /*
  2310.               * Restore the IP protocol field then save a copy of this
  2311.               * packet header.  (The checksum is zeroed in the copy so we
  2312.               * don't have to zero it each time we process a compressed
  2313.  
  2314.  
  2315.    Jacobson                                                       [Page 37]
  2316.  
  2317.    RFC 1144               Compressing TCP/IP Headers          February 1990
  2318.  
  2319.  
  2320.               * packet.
  2321.               */
  2322.              ip->ip_p = IPPROTO_TCP;
  2323.              hlen = ip->ip_hl;
  2324.              hlen += ((struct tcphdr *) & ((int *) ip)[hlen])->th_off;
  2325.              hlen <<= 2;
  2326.              BCOPY(ip, &cs->cs_ip, hlen);
  2327.              cs->cs_ip.ip_sum = 0;
  2328.              cs->cs_hlen = hlen;
  2329.              return (bufp);
  2330.  
  2331.         case TYPE_COMPRESSED_TCP:
  2332.              break;
  2333.         }
  2334.         /* We've got a compressed packet. */
  2335.         cp = bufp;
  2336.         changes = *cp++;
  2337.         if (changes & NEW_C) {
  2338.              /*
  2339.               * Make sure the state index is in range, then grab the
  2340.               * state. If we have a good state index, clear the 'discard'
  2341.               * flag.
  2342.               */
  2343.              if (*cp >= MAX_STATES)
  2344.                   goto bad;
  2345.  
  2346.              comp->flags &= ~SLF_TOSS;
  2347.              comp->last_recv = *cp++;
  2348.         } else {
  2349.              /*
  2350.               * This packet has an implicit state index.  If we've had a
  2351.               * line error since the last time we got an explicit state
  2352.               * index, we have to toss the packet.
  2353.               */
  2354.              if (comp->flags & SLF_TOSS)
  2355.                   return ((u_char *) 0);
  2356.         }
  2357.         /*
  2358.          * Find the state then fill in the TCP checksum and PUSH bit.
  2359.          */
  2360.         cs = &comp->rstate[comp->last_recv];
  2361.         hlen = cs->cs_ip.ip_hl << 2;
  2362.         th = (struct tcphdr *) & ((u_char *) &cs->cs_ip)[hlen];
  2363.         th->th_sum = htons((*cp << 8) | cp[1]);
  2364.         cp += 2;
  2365.         if (changes & TCP_PUSH_BIT)
  2366.              th->th_flags |= TH_PUSH;
  2367.         else
  2368.              th->th_flags &= ~TH_PUSH;
  2369.  
  2370.         /*
  2371.  
  2372.  
  2373.    Jacobson                                                       [Page 38]
  2374.  
  2375.    RFC 1144               Compressing TCP/IP Headers          February 1990
  2376.  
  2377.  
  2378.          * Fix up the state's ack, seq, urg and win fields based on the
  2379.          * changemask.
  2380.          */
  2381.         switch (changes & SPECIALS_MASK) {
  2382.         case SPECIAL_I:
  2383.              {
  2384.              register u_int i = ntohs(cs->cs_ip.ip_len) - cs->cs_hlen;
  2385.              th->th_ack = htonl(ntohl(th->th_ack) + i);
  2386.              th->th_seq = htonl(ntohl(th->th_seq) + i);
  2387.              }
  2388.              break;
  2389.  
  2390.         case SPECIAL_D:
  2391.              th->th_seq = htonl(ntohl(th->th_seq) + ntohs(cs->cs_ip.ip_len)
  2392.                           - cs->cs_hlen);
  2393.              break;
  2394.  
  2395.         default:
  2396.              if (changes & NEW_U) {
  2397.                   th->th_flags |= TH_URG;
  2398.                   DECODEU(th->th_urp)
  2399.              } else
  2400.                   th->th_flags &= ~TH_URG;
  2401.              if (changes & NEW_W)
  2402.                   DECODES(th->th_win)
  2403.              if (changes & NEW_A)
  2404.                   DECODEL(th->th_ack)
  2405.              if (changes & NEW_S)
  2406.                   DECODEL(th->th_seq)
  2407.              break;
  2408.         }
  2409.         /* Update the IP ID */
  2410.         if (changes & NEW_I)
  2411.              DECODES(cs->cs_ip.ip_id)
  2412.         else
  2413.              cs->cs_ip.ip_id = htons(ntohs(cs->cs_ip.ip_id) + 1);
  2414.  
  2415.         /*
  2416.          * At this point, cp points to the first byte of data in the packet.
  2417.          * If we're not aligned on a 4-byte boundary, copy the data down so
  2418.          * the IP & TCP headers will be aligned.  Then back up cp by the
  2419.          * TCP/IP header length to make room for the reconstructed header (we
  2420.          * assume the packet we were handed has enough space to prepend 128
  2421.          * bytes of header).  Adjust the lenth to account for the new header
  2422.          * & fill in the IP total length.
  2423.          */
  2424.         len -= (cp - bufp);
  2425.         if (len < 0)
  2426.              /*
  2427.               * we must have dropped some characters (crc should detect
  2428.               * this but the old slip framing won't)
  2429.  
  2430.  
  2431.    Jacobson                                                       [Page 39]
  2432.  
  2433.    RFC 1144               Compressing TCP/IP Headers          February 1990
  2434.  
  2435.  
  2436.               */
  2437.              goto bad;
  2438.  
  2439.         if ((int) cp & 3) {
  2440.              if (len > 0)
  2441.                   OVBCOPY(cp, (int) cp & ~3, len);
  2442.              cp = (u_char *) ((int) cp & ~3);
  2443.         }
  2444.         cp -= cs->cs_hlen;
  2445.         len += cs->cs_hlen;
  2446.         cs->cs_ip.ip_len = htons(len);
  2447.         BCOPY(&cs->cs_ip, cp, cs->cs_hlen);
  2448.  
  2449.         /* recompute the ip header checksum */
  2450.         {
  2451.              register u_short *bp = (u_short *) cp;
  2452.              for (changes = 0; hlen > 0; hlen -= 2)
  2453.                   changes += *bp++;
  2454.              changes = (changes & 0xffff) + (changes >> 16);
  2455.              changes = (changes & 0xffff) + (changes >> 16);
  2456.              ((struct ip *) cp)->ip_sum = ~changes;
  2457.         }
  2458.         return (cp);
  2459.  
  2460.    bad:
  2461.         comp->flags |= SLF_TOSS;
  2462.         return ((u_char *) 0);
  2463.    }
  2464.  
  2465.  
  2466.  
  2467.  
  2468.  
  2469.  
  2470.  
  2471.  
  2472.  
  2473.  
  2474.  
  2475.  
  2476.  
  2477.  
  2478.  
  2479.  
  2480.  
  2481.  
  2482.  
  2483.  
  2484.  
  2485.  
  2486.  
  2487.  
  2488.  
  2489.    Jacobson                                                       [Page 40]
  2490.  
  2491.    RFC 1144               Compressing TCP/IP Headers          February 1990
  2492.  
  2493.  
  2494.    A.4  Initialization
  2495.  
  2496.    This routine initializes the state structure for both the transmit and
  2497.    receive halves of some serial line.  It must be called each time the
  2498.    line is brought up.
  2499.  
  2500.    void
  2501.    sl_compress_init(comp)
  2502.         struct slcompress *comp;
  2503.    {
  2504.         register u_int i;
  2505.         register struct cstate *tstate = comp->tstate;
  2506.  
  2507.         /*
  2508.          * Clean out any junk left from the last time line was used.
  2509.          */
  2510.         bzero((char *) comp, sizeof(*comp));
  2511.         /*
  2512.          * Link the transmit states into a circular list.
  2513.          */
  2514.         for (i = MAX_STATES - 1; i > 0; --i) {
  2515.              tstate[i].cs_id = i;
  2516.              tstate[i].cs_next = &tstate[i - 1];
  2517.         }
  2518.         tstate[0].cs_next = &tstate[MAX_STATES - 1];
  2519.         tstate[0].cs_id = 0;
  2520.         comp->last_cs = &tstate[0];
  2521.         /*
  2522.          * Make sure we don't accidentally do CID compression
  2523.          * (assumes MAX_STATES < 255).
  2524.          */
  2525.         comp->last_recv = 255;
  2526.         comp->last_xmit = 255;
  2527.    }
  2528.  
  2529.  
  2530.    A.5  Berkeley Unix dependencies
  2531.  
  2532.    Note:  The following is of interest only if you are trying to bring the
  2533.    sample code up on a system that is not derived from 4BSD (Berkeley
  2534.    Unix).
  2535.  
  2536.    The code uses the normal Berkeley Unix header files (from
  2537.    /usr/include/netinet) for definitions of the structure of IP and TCP
  2538.    headers.  The structure tags tend to follow the protocol RFCs closely
  2539.    and should be obvious even if you do not have access to a 4BSD
  2540.    system./48/
  2541.  
  2542.    ----------------------------
  2543.     48. In the event they are not obvious, the header files (and all the
  2544.    Berkeley networking code) can be anonymous ftp'd from host
  2545.  
  2546.  
  2547.    Jacobson                                                       [Page 41]
  2548.  
  2549.    RFC 1144               Compressing TCP/IP Headers          February 1990
  2550.  
  2551.  
  2552.    The macro BCOPY(src, dst, amt) is invoked to copy amt bytes from src to
  2553.    dst.  In BSD, it translates into a call to bcopy.  If you have the
  2554.    misfortune to be running System-V Unix, it can be translated into a call
  2555.    to memcpy.  The macro OVBCOPY(src, dst, amt) is used to copy when src
  2556.    and dst overlap (i.e., when doing the 4-byte alignment copy).  In the
  2557.    BSD kernel, it translates into a call to ovbcopy.  Since AT&T botched
  2558.    the definition of memcpy, this should probably translate into a copy
  2559.    loop under System-V.
  2560.  
  2561.    The macro BCMP(src, dst, amt) is invoked to compare amt bytes of src and
  2562.    dst for equality.  In BSD, it translates into a call to bcmp.  In
  2563.    System-V, it can be translated into a call to memcmp or you can write a
  2564.    routine to do the compare.  The routine should return zero if all bytes
  2565.    of src and dst are equal and non-zero otherwise.
  2566.  
  2567.    The routine ntohl(dat) converts (4 byte) long dat from network byte
  2568.    order to host byte order.  On a reasonable cpu this can be the no-op
  2569.    macro:
  2570.                            #define ntohl(dat) (dat)
  2571.  
  2572.    On a Vax or IBM PC (or anything with Intel byte order), you will have to
  2573.    define a macro or routine to rearrange bytes.
  2574.  
  2575.    The routine ntohs(dat) is like ntohl but converts (2 byte) shorts
  2576.    instead of longs.  The routines htonl(dat) and htons(dat) do the inverse
  2577.    transform (host to network byte order) for longs and shorts.
  2578.  
  2579.    A struct mbuf is used in the call to sl_compress_tcp because that
  2580.    routine needs to modify both the start address and length if the
  2581.    incoming packet is compressed.  In BSD, an mbuf is the kernel's buffer
  2582.    management structure.  If other systems, the following definition should
  2583.    be sufficient:
  2584.  
  2585.             struct mbuf {
  2586.                     u_char  *m_off; /* pointer to start of data */
  2587.                     int     m_len;  /* length of data */
  2588.             };
  2589.  
  2590.             #define mtod(m, t) ((t)(m->m_off))
  2591.  
  2592.  
  2593.  
  2594.  
  2595.  
  2596.  
  2597.  
  2598.  
  2599.  
  2600.  
  2601.    ----------------------------
  2602.    ucbarpa.berkeley.edu, files pub/4.3/tcp.tar and pub/4.3/inet.tar.
  2603.  
  2604.  
  2605.    Jacobson                                                       [Page 42]
  2606.  
  2607.    RFC 1144               Compressing TCP/IP Headers          February 1990
  2608.  
  2609.  
  2610.    B  Compatibility with past mistakes
  2611.  
  2612.  
  2613.    When combined with the modern PPP serial line protocol[9], the use of
  2614.    header compression is automatic and invisible to the user.
  2615.    Unfortunately, many sites have existing users of the SLIP described in
  2616.    [12] which doesn't allow for different protocol types to distinguish
  2617.    header compressed packets from IP packets or for version numbers or an
  2618.    option exchange that could be used to automatically negotiate header
  2619.    compression.
  2620.  
  2621.    The author has used the following tricks to allow header compressed SLIP
  2622.    to interoperate with the existing servers and clients.  Note that these
  2623.    are hacks for compatibility with past mistakes and should be offensive
  2624.    to any right thinking person.  They are offered solely to ease the pain
  2625.    of running SLIP while users wait patiently for vendors to release PPP.
  2626.  
  2627.  
  2628.    B.1  Living without a framing `type' byte
  2629.  
  2630.    The bizarre packet type numbers in sec. A.1 were chosen to allow a
  2631.    `packet type' to be sent on lines where it is undesirable or impossible
  2632.    to add an explicit type byte.  Note that the first byte of an IP packet
  2633.    always contains `4' (the IP protocol version) in the top four bits.  And
  2634.    that the most significant bit of the first byte of the compressed header
  2635.    is ignored.  Using the packet types in sec. A.1, the type can be encoded
  2636.    in the most significant bits of the outgoing packet using the code
  2637.  
  2638.                     p->dat[0] |= sl_compress_tcp(p, comp);
  2639.  
  2640.     and decoded on the receive side by
  2641.  
  2642.                   if (p->dat[0] & 0x80)
  2643.                           type = TYPE_COMPRESSED_TCP;
  2644.                   else if (p->dat[0] >= 0x70) {
  2645.                           type = TYPE_UNCOMPRESSED_TCP;
  2646.                           p->dat[0] &=~ 0x30;
  2647.                   } else
  2648.                           type = TYPE_IP;
  2649.                   status = sl_uncompress_tcp(p, type, comp);
  2650.  
  2651.  
  2652.  
  2653.  
  2654.  
  2655.  
  2656.    B.2  Backwards compatible SLIP servers
  2657.  
  2658.    The SLIP described in [12] doesn't include any mechanism that could be
  2659.    used to automatically negotiate header compression.  It would be nice to
  2660.  
  2661.  
  2662.  
  2663.    Jacobson                                                       [Page 43]
  2664.  
  2665.    RFC 1144               Compressing TCP/IP Headers          February 1990
  2666.  
  2667.  
  2668.    allow users of this SLIP to use header compression but, when users of
  2669.    the two SLIP varients share a common server, it would be annoying and
  2670.    difficult to manually configure both ends of each connection to enable
  2671.    compression.  The following procedure can be used to avoid manual
  2672.    configuration.
  2673.  
  2674.    Since there are two types of dial-in clients (those that implement
  2675.    compression and those that don't) but one server for both types, it's
  2676.    clear that the server will be reconfiguring for each new client session
  2677.    but clients change configuration seldom if ever.  If manual
  2678.    configuration has to be done, it should be done on the side that changes
  2679.    infrequently --- the client.  This suggests that the server should
  2680.    somehow learn from the client whether to use header compression.
  2681.    Assuming symmetry (i.e., if compression is used at all it should be used
  2682.    both directions) the server can use the receipt of a compressed packet
  2683.    from some client to indicate that it can send compressed packets to that
  2684.    client.  This leads to the following algorithm:
  2685.  
  2686.    There are two bits per line to control header compression:  allowed and
  2687.    on.  If on is set, compressed packets are sent, otherwise not.  If
  2688.    allowed is set, compressed packets can be received and, if an
  2689.    UNCOMPRESSED_TCP packet arrives when on is clear, on will be set./49/
  2690.    If a compressed packet arrives when allowed is clear, it will be
  2691.    ignored.
  2692.  
  2693.    Clients are configured with both bits set (allowed is always set if on
  2694.    is set) and the server starts each session with allowed set and on
  2695.    clear.  The first compressed packet from the client (which must be a
  2696.    UNCOMPRESSED_TCP packet) turns on compression for the server.
  2697.  
  2698.  
  2699.  
  2700.  
  2701.  
  2702.  
  2703.  
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.  
  2711.  
  2712.  
  2713.    ----------------------------
  2714.     49. Since [12] framing doesn't include error detection, one should be
  2715.    careful not to `false trigger' compression on the server.  The
  2716.    UNCOMPRESSED_TCP packet should checked for consistency (e.g., IP
  2717.    checksum correctness) before compression is enabled.  Arrival of
  2718.    COMPRESSED_TCP packets should not be used to enable compression.
  2719.  
  2720.  
  2721.    Jacobson                                                       [Page 44]
  2722.  
  2723.    RFC 1144               Compressing TCP/IP Headers          February 1990
  2724.  
  2725.  
  2726.    C  More aggressive compression
  2727.  
  2728.  
  2729.    As noted in sec. 3.2.2, easily detected patterns exist in the stream of
  2730.    compressed headers, indicating that more compression could be done.
  2731.    Would this be worthwhile?
  2732.  
  2733.    The average compressed datagram has only seven bits of header./50/  The
  2734.    framing must be at least one bit (to encode the `type') and will
  2735.    probably be more like two to three bytes.  In most interesting cases
  2736.    there will be at least one byte of data.  Finally, the end-to-end
  2737.    check---the TCP checksum---must be passed through unmodified./51/
  2738.  
  2739.    The framing, data and checksum will remain even if the header is
  2740.    completely compressed out so the change in average packet size is, at
  2741.    best, four bytes down to three bytes and one bit --- roughly a 25%
  2742.    improvement in delay./52/  While this may seem significant, on a 2400
  2743.    bps line it means that typing echo response takes 25 rather than 29 ms.
  2744.    At the present stage of human evolution, this difference is not
  2745.    detectable.
  2746.  
  2747.    However, the author sheepishly admits to perverting this compression
  2748.    scheme for a very special case data-acquisition problem:  We had an
  2749.    instrument and control package floating at 200KV, communicating with
  2750.    ground level via a telemetry system.  For many reasons (multiplexed
  2751.    communication, pipelining, error recovery, availability of well tested
  2752.    implementations, etc.), it was convenient to talk to the package using
  2753.    TCP/IP. However, since the primary use of the telemetry link was data
  2754.    acquisition, it was designed with an uplink channel capacity <0.5% the
  2755.    downlink's.  To meet application delay budgets, data packets were 100
  2756.    bytes and, since TCP acks every other packet, the relative uplink
  2757.    bandwidth for acks is a/200 where `a' is the total size of ack packets.
  2758.    Using the scheme in this paper, the smallest ack is four bytes which
  2759.    would imply an uplink bandwidth 2% of the downlink.  This wasn't
  2760.  
  2761.    ----------------------------
  2762.     50. Tests run with several million packets from a mixed traffic load
  2763.    (i.e., statistics kept on a year's traffic from my home to work) show
  2764.    that 80% of packets use one of the two special encodings and, thus, the
  2765.    only header is the change mask.
  2766.     51. If someone tries to sell you a scheme that compresses the TCP
  2767.    checksum `Just say no'.  Some poor fool has yet to have the sad
  2768.    experience that reveals the end-to-end argument is gospel truth.  Worse,
  2769.    since the fool is subverting your end-to-end error check, you may pay
  2770.    the price for this education and they will be none the wiser.  What does
  2771.    it profit a man to gain two byte times of delay and lose peace of mind?
  2772.     52. Note again that we must be concerned about interactive delay to be
  2773.    making this argument:  Bulk data transfer performance will be dominated
  2774.    by the time to send the data and the difference between three and four
  2775.    byte headers on a datagram containing tens or hundreds of data bytes is,
  2776.    practically, no difference.
  2777.  
  2778.  
  2779.    Jacobson                                                       [Page 45]
  2780.  
  2781.    RFC 1144               Compressing TCP/IP Headers          February 1990
  2782.  
  2783.  
  2784.    possible so we used the scheme described in footnote 15:  If the first
  2785.    bit of the frame was one, it meant `same compressed header as last
  2786.    time'.  Otherwise the next two bits gave one of the types described in
  2787.    sec. 3.2.  Since the link had excellent forward error correction and
  2788.    traffic made only a single hop, the TCP checksum was compressed out
  2789.    (blush!) of the `same header' packet types/53/ so the total header size
  2790.    for these packets was one bit.  Over several months of operation, more
  2791.    than 99% of the 40 byte TCP/IP headers were compressed down to one
  2792.    bit./54/
  2793.  
  2794.  
  2795.    D  Security Considerations
  2796.  
  2797.  
  2798.    Security considerations are not addressed in this memo.
  2799.  
  2800.  
  2801.    E  Author's address
  2802.  
  2803.  
  2804.        Address:  Van Jacobson
  2805.                  Real Time Systems Group
  2806.                  Mail Stop 46A
  2807.                  Lawrence Berkeley Laboratory
  2808.                  Berkeley, CA 94720
  2809.  
  2810.        Phone:    Use email (author ignores his phone)
  2811.  
  2812.        EMail:    van@helios.ee.lbl.gov
  2813.  
  2814.  
  2815.  
  2816.  
  2817.  
  2818.  
  2819.  
  2820.  
  2821.  
  2822.  
  2823.  
  2824.  
  2825.  
  2826.  
  2827.    ----------------------------
  2828.     53. The checksum was re-generated in the decompressor and, of course,
  2829.    the `toss' logic was made considerably more aggressive to prevent error
  2830.    propagation.
  2831.     54. We have heard the suggestion that `real-time' needs require
  2832.    abandoning TCP/IP in favor of a `light-weight' protocol with smaller
  2833.    headers.  It is difficult to envision a protocol that averages less than
  2834.    one header bit per packet.
  2835.  
  2836.  
  2837.    Jacobson                                                       [Page 46]
  2838.  
  2839.